Skip to content

Instantly share code, notes, and snippets.

@joshweinstein
Created February 27, 2013 00:05
Show Gist options
  • Save joshweinstein/5043584 to your computer and use it in GitHub Desktop.
Save joshweinstein/5043584 to your computer and use it in GitHub Desktop.
elastic search: setup for autocomplete
curl -XPUT 'http://127.0.0.1:9200/argmaps-development/?pretty=1' -d '
{
"mappings" : {
"questions" : {
"properties" : {
"question_text" : {
"fields" : {
"ngrams" : {
"type" : "string",
"analyzer" : "my_ngram"
},
"question_text" : {
"type" : "string",
"analyzer" : "english"
}
},
"type" : "multi_field"
}
}
}
},
"settings" : {
"analysis" : {
"filter" : {
"mynGram" : {
"max_gram" : 10,
"min_gram" : 2,
"type" : "edge_ngram"
}
},
"analyzer" : {
"my_ngram" : {
"filter" : [
"stop",
"lowercase",
"mynGram"
],
"tokenizer" : "standard"
}
}
}
}
}
'
curl -XPOST 'http://127.0.0.1:9200/argmaps-development/questions?pretty=1' -d '{ "question_text" : "meet entrepreneurs" }'
curl -XPOST 'http://127.0.0.1:9200/argmaps-development/questions?pretty=1' -d '{ "question_text" : "play basketball"}'
curl -XPOST 'http://127.0.0.1:9200/argmaps-development/questions?pretty=1' -d '{ "question_text" : "trekking"}'
curl -XPOST 'http://127.0.0.1:9200/argmaps-development/_refresh?pretty=1'
curl -XGET 'http://127.0.0.1:9200/argmaps-development/questions/_search?pretty=1' -d '
{
"query" : {
"bool" : {
"should" : [
{
"text" : {
"question_text.ngrams" : {
"operator" : "and",
"query" : "trek"
}
}
},
{
"text" : {
"question_text" : "trek"
}
}
]
}
},
"highlight" : {
"fields" : {
"question_text.ngrams" : {},
"question_text" : {}
}
}
}
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment