Skip to content

Instantly share code, notes, and snippets.

@dadoonet
Created July 8, 2013 19:40
Show Gist options
  • Save dadoonet/5951841 to your computer and use it in GitHub Desktop.
Save dadoonet/5951841 to your computer and use it in GitHub Desktop.
Using ngram with multifield
# Delete index
curl -XDELETE 'http://localhost:9200/pms/' ; echo
curl -XPUT 'http://localhost:9200/pms/' -d '{
"analysis" : {
"analyzer" : {
"auto_complete" : {
"type" : "custom",
"tokenizer" : "custom_edgeNGram",
"filter" : ["lowercase","custom_ngram"]
}
},
"tokenizer" : {
"custom_edgeNGram" : {
"type" : "edgeNGram",
"min_gram" : 2,
"max_gram" : 5
}
},
"filter" : {
"custom_ngram" : {
"type" : "nGram",
"min_gram" : 2,
"max_gram" : 5
}
}
}
}' ; echo
# Analyze MOUSE
curl -XGET 'localhost:9200/pms/_analyze?analyzer=auto_complete&pretty' -d 'MOUSE' ; echo
# Analyze MOU
curl -XGET 'localhost:9200/pms/_analyze?analyzer=auto_complete&pretty' -d 'MOU' ; echo
# Create type
curl -XPUT 'http://localhost:9200/pms/results/_mapping' -d '{
"results" : {
"properties" : {
"search_column" : {
"type" : "multi_field",
"fields" : {
"search_column" : {"type" : "string", "index" : "analyzed", "include_in_all" : "true"},
"autocomplete" : {"type" : "string", "index" : "analyzed", "include_in_all" : "true", "analyzer":"auto_complete"}
}
}
}
}
}' ; echo
# Put document
curl -XPUT 'http://localhost:9200/pms/results/1' -d '{
"search_column": "MOUSE"
}' ; echo
curl -XPUT 'http://localhost:9200/pms/results/2?refresh=true' -d '{
"search_column": "MOUSE"
}' ; echo
# Searching
curl -XGET 'localhost:9200/pms/results/_search?pretty' -d '{
"query" : {
"match" : {
"search_column" : "MOUSE"
}
}
}
' ; echo
curl -XGET 'localhost:9200/pms/results/_search?pretty' -d '{
"query" : {
"match" : {
"search_column.autocomplete" : "MOUSE"
}
}
}
' ; echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment