forked from codingexplained/complete-guide-to-elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
216 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Adding mappings to existing indices | ||
|
||
## Adding mapping for `discount` field | ||
|
||
``` | ||
PUT /product/default/_mapping | ||
{ | ||
"properties": { | ||
"discount": { | ||
"type": "double" | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Retrieving mapping | ||
|
||
``` | ||
GET /product/default/_mapping | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Adding multi-fields mappings | ||
|
||
## Adding mappings | ||
|
||
``` | ||
PUT /product/default/_mapping | ||
{ | ||
"properties": { | ||
"description": { | ||
"type": "text" | ||
}, | ||
"name": { | ||
"type": "text", | ||
"fields": { | ||
"keyword": { | ||
"type": "keyword" | ||
} | ||
} | ||
}, | ||
"tags": { | ||
"type": "text", | ||
"fields": { | ||
"keyword": { | ||
"type": "keyword" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Retrieving mapping | ||
|
||
``` | ||
GET /product/default/_mapping | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Changing existing mappings | ||
|
||
## Deleting the index | ||
|
||
``` | ||
DELETE /product | ||
``` | ||
|
||
## Creating index with mappings | ||
|
||
``` | ||
PUT /product | ||
{ | ||
"mappings": { | ||
"default": { | ||
"dynamic": false, | ||
"properties": { | ||
"in_stock": { | ||
"type": "integer" | ||
}, | ||
"is_active": { | ||
"type": "boolean" | ||
}, | ||
"price": { | ||
"type": "integer" | ||
}, | ||
"sold": { | ||
"type": "long" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Defining custom date formats | ||
|
||
## Date mapping with `year` format | ||
|
||
``` | ||
PUT /product/default/_mapping | ||
{ | ||
"properties": { | ||
"created": { | ||
"type": "date", | ||
"format": "year" | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Date mapping with `strict_year` format | ||
|
||
``` | ||
PUT /product/default/_mapping | ||
{ | ||
"properties": { | ||
"created": { | ||
"type": "date", | ||
"format": "strict_year" | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Date mapping with explicit default format | ||
|
||
``` | ||
PUT /product/default/_mapping | ||
{ | ||
"properties": { | ||
"created": { | ||
"type": "date", | ||
"format": "strict_date_optional_time||epoch_millis" | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Date mapping with date and optional time | ||
|
||
``` | ||
PUT /product/default/_mapping | ||
{ | ||
"properties": { | ||
"created": { | ||
"type": "date", | ||
"format": "yyyy/MM/dd HH:mm:ss||yyyy/MM/dd" | ||
} | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Dynamic mapping | ||
|
||
## Retrieving mapping | ||
|
||
``` | ||
GET /product/default/_mapping | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Picking up new fields without dynamic mapping | ||
|
||
## Adding test document | ||
|
||
``` | ||
POST /product/default/2000 | ||
{ | ||
"description": "Test", | ||
"discount": 20 | ||
} | ||
``` | ||
|
||
## Adding mapping for `discount` field | ||
|
||
``` | ||
PUT /product/default/_mapping | ||
{ | ||
"properties": { | ||
"discount": { | ||
"type": "integer" | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Querying the `description` field | ||
|
||
``` | ||
GET /product/default/_search | ||
{ | ||
"query": { | ||
"match": { | ||
"description": "Test" | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Querying the `discount` field | ||
|
||
``` | ||
GET /product/default/_search | ||
{ | ||
"query": { | ||
"term": { | ||
"discount": 20 | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Picking up new mappings for documents | ||
|
||
``` | ||
POST /product/_update_by_query?conflicts=proceed | ||
``` | ||
|
||
## Deleting the test document | ||
|
||
``` | ||
DELETE /product/default/2000 | ||
``` |