As we can see in the below simple ElasticSearch for text "Baby Oil" I get HIT-TOTAL of 8616. Is there a way I can get the HITs in details like below . Technically I want permutation of hit count for all words in search.
HIT TOTAL of 8618
HIT BABY of 5000
HIT OIL of 3618
HIT BABY AND OIL of 4500
Update
After using the "fielddata": true , we get the count for all the keywords, instead of keywords used in the search
CodePudding user response:
You can use Filter aggregation
A multi-bucket aggregation where each bucket contains the documents that match a query.
Query
{
"query": {
"query_string": {
"default_field": "rawtext",
"query": "baby oil"
}
},
"aggs": {
"count": {
"filters": {
"filters": {
"baby": {
"match": {
"rawtext": "baby"
}
},
"oil": {
"match": {
"rawtext": "oil"
}
},
"baby oil": {
"match": {
"rawtext":{
"query": "baby oil",
"operator": "and"
}
}
}
}
}
}
}
}
Result
"aggregations" : {
"count" : {
"buckets" : {
"baby" : {
"doc_count" : 2
},
"baby oil" : {
"doc_count" : 1
},
"oil" : {
"doc_count" : 3
}
}
}
}