Skip to content

Instantly share code, notes, and snippets.

@rabb-bit
Created August 22, 2016 10:45
Show Gist options
  • Save rabb-bit/b6f9ebcebc41693e4b007cba649b67c7 to your computer and use it in GitHub Desktop.
Save rabb-bit/b6f9ebcebc41693e4b007cba649b67c7 to your computer and use it in GitHub Desktop.
{
"mappings":{
"item":{
"properties":{
"productName":{
"fields":{
"partial":{
"search_analyzer":"full_name",
"analyzer":"partial_name",
"type":"string"
},
"partial_back":{
"search_analyzer":"full_name",
"analyzer":"partial_name_back", // changed from index_analyzer to analzyer starting ES 2.0 -remove this
"type":"string"
},
"partial_middle":{
"search_analyzer":"full_name",
"analyzer":"partial_middle_name",
"type":"string"
},
"productName":{
"type":"string",
"analyzer":"full_name"
}
},
"type":"multi_field"
},
"productID":{
"type":"string",
"analyzer":"simple"
},
"warehouse":{
"type":"string",
"analyzer":"simple"
},
"vendor":{
"type":"string",
"analyzer":"simple"
},
"productDescription":{
"type":"string",
"analyzer":"full_name"
},
"categories":{
"type":"string",
"analyzer":"simple"
},
"stockLevel":{
"type":"integer",
"index":"not_analyzed"
},
"cost":{
"type":"float",
"index":"not_analyzed"
}
}
}
},
"settings":{
"analysis":{
"filter":{
"name_ngrams":{
"side":"front",
"max_gram":50,
"min_gram":2,
"type":"edgeNGram"
},
"name_ngrams_back":{
"side":"back",
"max_gram":50,
"min_gram":2,
"type":"edgeNGram"
},
"name_middle_ngrams":{
"type":"nGram",
"max_gram":50,
"min_gram":2
}
},
"analyzer":{
"full_name":{
"filter":[
"standard",
"lowercase",
"asciifolding"
],
"type":"custom",
"tokenizer":"standard"
},
"partial_name":{
"filter":[
"standard",
"lowercase",
"asciifolding",
"name_ngrams"
],
"type":"custom",
"tokenizer":"standard"
},
"partial_name_back":{
"filter":[
"standard",
"lowercase",
"asciifolding",
"name_ngrams_back"
],
"type":"custom",
"tokenizer":"standard"
},
"partial_middle_name":{
"filter":[
"standard",
"lowercase",
"asciifolding",
"name_middle_ngrams"
],
"type":"custom",
"tokenizer":"standard"
}
}
}
}
}
/*-----------------Example query:----------------------*/
{
"size":20,
"from":0,
"sort":[
"_score"
],
"query":{
"filtered":{
"query":{
"bool":{
"should":[
{
"match":{
"productName":{
"boost":5,
"query":"test query",
"type":"phrase"
}
}
},
{
"match":{
"productName.partial":{
"boost":1,
"query":"test query"
}
}
},
{
"match":{
"productName.partial_middle":{
"boost":1,
"query":"test query"
}
}
},
{
"match":{
"productName.partial_back":{
"boost":1,
"query":"test query"
}
}
}
]
}
},
"filter":{
"bool":{
"must":[
{
"terms":{
"warehouse":[
"international",
"usa",
"aus",
"de"
]
}
},
{
"range":{
"stockLevel":{
"gt":"0"
}
}
}
]
}
}
}
}
}
@rabb-bit
Copy link
Author

Shared it to public due to I have hard time finding an example like this. I updated this example I found for ver 2.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment