Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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