Skip to content

Instantly share code, notes, and snippets.

@mawalu
Last active July 12, 2016 13:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mawalu/9dee10a97fcfdec133729737b27d034b to your computer and use it in GitHub Desktop.
Save mawalu/9dee10a97fcfdec133729737b27d034b to your computer and use it in GitHub Desktop.
Elasticsearch ngram problem
{
"settings" : {
"analysis" : {
"filter" : {
"ngram" : {
"min_gram" : 2,
"max_gram" : 20,
"token_chars" : [
"letter",
"digit",
"punctuation",
"symbol"
],
"type" : "ngram"
}
},
"analyzer" : {
"whitespace_analyzer" : {
"tokenizer" : "whitespace",
"type" : "custom",
"filter" : [
"lowercase",
"asciifolding"
]
},
"ngram_analyzer" : {
"filter" : [
"asciifolding",
"lowercase",
"ngram"
],
"type" : "custom",
"tokenizer" : "whitespace"
}
}
}
},
"mapping" : {
"person" : {
"_all" : {
"search_analyzer" : "whitespace_analyzer",
"analyzer" : "ngram_analyzer"
},
"properties" : {
"firstname" : {
"analyzer" : "ngram_analyzer",
"search_analyzer" : "whitespace_analyzer"
}
}
}
}
}
{
"firstname":"Terrill",
"lastname":"Parker",
"id":712,
"title":"Mr.",
"nickname":"",
"gender":"male",
"birthday":"1970-07-12",
"companies":[
"Abshire, Fadel and Kiehn",
"Zemlak Ltd",
"McDermott, Schuppe and Mayer",
"Ledner, Rosenbaum and Maggio",
"Schoen PLC",
"Hills LLC",
"Tromp, Abernathy and Kuvalis",
"Toy, Gusikowski and Mohr",
"Hyatt-Flatley",
"Rippin, Batz and Ondricka",
"Jenkins-Corwin",
"Ratke PLC"
],
"emailAddresses":[
"john66@doe.com",
"pdoe@doe.info"
],
"addresses":[
"Doe Street 31, 35283 JaneVille",
"Doe Street 78, 46721 JohnVille",
"Doe Street 48, 39953 JohnVille",
"Doe Street 24, 31388 JohnVille",
"Doe Street 84, 35932 JohnVille"
],
"phoneNumbers":[
"747-058-484",
"027-478-036"
]
}
{
"firstname":"Austen",
"lastname":"Braun",
"id":701,
"title":"Mr.",
"nickname":"",
"gender":"male",
"birthday":"2008-05-15",
"companies":[
"Abshire, Fadel and Kiehn",
"Wolf-Bogan",
"Kohler-Langosh",
"Howe, Skiles and Boyer",
"Rippin, Batz and Ondricka",
"Gislason-Kirlin"
],
"emailAddresses":[
],
"addresses":[
"Doe Street 68, 28012 JaneVille",
"Doe Street 12, 78992 JohnVille",
"Doe Street 23, 75805 JaneVille",
"Doe Street 95, 46066 JohnVille",
"Doe Street 72, 28754 JohnVille"
],
"phoneNumbers":[
]
}
{
"size":10,
"query":{
"match":{
"_all":{
"query":"Aust"
}
}
}
}

Create index

curl -X PUT -d @create_index.json http://127.0.0.1:9200/persons

Load demo data

curl -X PUT -d @demo_1.json http://127.0.0.1:9200/persons/person/712
curl -X PUT -d @demo_2.json http://127.0.0.1:9200/persons/person/701

Query

curl -X GET -d @query.json http://127.0.0.1:9200/persons/_search
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment