Skip to content

Instantly share code, notes, and snippets.

@spaghetticode
Last active October 18, 2018 08:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spaghetticode/807816787fe1c22c384b to your computer and use it in GitHub Desktop.
Save spaghetticode/807816787fe1c22c384b to your computer and use it in GitHub Desktop.
Beginning Elasticsearch - mappings and analyzers
# 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