Last active
October 18, 2018 08:38
-
-
Save spaghetticode/807816787fe1c22c384b to your computer and use it in GitHub Desktop.
Beginning Elasticsearch - mappings and analyzers
This file contains hidden or 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
# Record insertion: | |
PUT /examples/movies/1 | |
{ | |
"title": "Saving Private Ryan", | |
"description": "A war movie set during the invasion of Normandy" | |
} | |
# see current mappings: | |
GET /examples/_mapping | |
# See how text is analyzed by default: | |
GET /_analyze?/analyzer=standard | |
{ "Saving private Ryan" } | |
# See how text is analyzed in the context of the field "title": | |
GET /examples/_analyze?field=title | |
{ "Saving private Ryan"} | |
# See how text is analyzed with the english analyzer: | |
GET /_analyze?analyzer=english | |
{ "Saving private Ryan" } | |
# Simple match query, successful: | |
GET /examples/movies/_search | |
{ | |
"query": { | |
"match": { "title": "saving" } | |
} | |
} | |
# Simple match query, unsuccessful: | |
GET /examples/movies/_search | |
{ | |
"query": { | |
"match": { "title": "save" } | |
} | |
} | |
# Update "movies" mapping: | |
PUT /examples/movies/_mapping | |
{ | |
"properties": { | |
"title": { | |
"type": "string", | |
"fields": { | |
"en": { | |
"type": "string", | |
"analyzer": "english" | |
} | |
} | |
} | |
} | |
} | |
# Update record, adding "title.en" field: | |
POST /examples/movies/1/_update | |
{ | |
"doc": { | |
"title.en": "Saving private Ryan" | |
} | |
} | |
# Query on "title.en", a field that uses the english analyzer: | |
GET /examples/movies/_search | |
{ | |
"query": { | |
"match": { | |
"title.en": "save" | |
} | |
} | |
} | |
# multi_match query, allows multiple fields search: | |
GET /examples/movies/_search | |
{ | |
"query": { | |
multi_"match": { | |
"fields": "title*", | |
"query": "save" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment