I am new to Elasticsearch, And we are working on a requirement,where document in the elasticsearch will be fetched based on the match types like fuzzyMatch,Wordmatch etc...
We are facing performance issues here, when document is matched for one match type, document should come out of the "bool" query, but it is participating in all match types and giving me the all match types result, I tried nested bool query to make it participate in single match types and exit when matched else move to next match types.
I tried following this blog.
[https://www.elastic.co/blog/lost-in-translation-boolean-operations-and-filters-in-the-bool-query][1]
Even this is resulting me the same Reesult..
Please find the below sample code.
{
"size": 10000,
"query": {
"function_score": {
"score_mode": "sum",
"functions": [
{
"filter": {
"bool": {
"should": [
{
"bool": {
"should": [
{
"match": {
"4": {
"fuzziness": "AUTO",
"query": "kavan",
"minimum_should_match": "50%",
"_name": "4.fuzzyMatch"
}
}
},
{
"match": {
"4": {
"query": "kavan",
"minimum_should_match": "50%",
"_name": "4.wordMatch"
}
}
}
]
}
},
{
"bool": {
"should": [
{
"match": {
"4.subStringMatch": {
"query": "kavan",
"minimum_should_match": "50%",
"_name": "4.subStringMatch"
}
}
},
{
"match": {
"4.phoneticMatch": {
"query": "kavan",
"minimum_should_match": "50%",
"_name": "4.phoneticMatch"
}
}
}
]
}
},
{
"match": {
"4.exactMatch": "kavan"
}
}
]
}
},
"weight": 50
}
]
}
}
}
Actual output is:
"hits": {
"total": 94,
"max_score": 50.0,
"hits": [{
"_index": "6_1028",
"_type": "6_1028",
"_id": "14",
"_score": 50.0,
"_source": {
"1": 14,
"@timestamp": "2018-05-18T06:57:02.540Z",
"4": "kavana",
"6": "Vastrad",
"7": "Indiranagar",
"@version": "1",
"type": "1028",
"10": "Bangalore"
},
"matched_queries": ["4.phoneticMatch", "4.fuzzyMatch", "4.subStringMatch"]
}, {
"_index": "6_1028",
"_type": "6_1028",
"_id": "52",
"_score": 50.0,
"_source": {
"1": 52,
"@timestamp": "2018-05-18T06:57:02.559Z",
"4": "kavana",
"6": "Vastrad",
"7": "Indiranagar",
"@version": "1",
"type": "1028",
"10": "Bangalore"
},
"matched_queries": ["4.phoneticMatch", "4.fuzzyMatch", "4.subStringMatch"]
}, {
"_index": "6_1028",
"_type": "6_1028",
"_id": "53",
"_score": 50.0,
"_source": {
"1": 53,
"@timestamp": "2018-05-18T06:57:02.559Z",
"4": "kavana",
"6": "Vastrad",
"7": "Indiranagar",
"@version": "1",
"type": "1028",
"10": "Bangalore"
},
"matched_queries": ["4.phoneticMatch", "4.fuzzyMatch", "4.subStringMatch"]
}
}
Expected output is:
"hits": {
"total": 94,
"max_score": 50.0,
"hits": [{
"_index": "6_1028",
"_type": "6_1028",
"_id": "14",
"_score": 50.0,
"_source": {
"1": 14,
"@timestamp": "2018-05-18T06:57:02.540Z",
"4": "kavana",
"6": "Vastrad",
"7": "Indiranagar",
"@version": "1",
"type": "1028",
"10": "Bangalore"
},
"matched_queries": ["4.phoneticMatch"]
}
With only one match type in matched_queries
Note : Match types can be seen in matched_queries block.
Any suggestions in this regard are appreciated..