My query :
POST /testqueryidx/testQuery/_search
{
"size" : 10,
"query" : {
"bool" : {
"must" : [ {
"multi_match": {
"query": "sales*",
"fields": ["skills"]
}
}, {
"query_string" : {
"query" : "jay12",
"fields" : [ "idNum" ]
}
} ]
}
},
"aggregations" : {
"aggs" : {
"terms" : {
"field" : "skills_sort",
"size" : 0,
"order" : {
"_term" : "asc"
}
}
}
}
}
Query Results :
{
"took": 3,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 0.9734945,
"hits": [
{
"_index": "testqueryidx",
"_type": "testQuery",
"_id": "56909fbdaecb813e8c64e1e8",
"_score": 0.9734945,
"_source": {
"skills": [
"Account Management",
"Sales force",
"Adobe Creative Suite"
],
"_id": "56909fbdaecb813e8c64e1e8",
"idNum": "jay12"
}
}
]
},
"aggregations": {
"aggs": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "Account Management",
"doc_count": 1
},
{
"key": "Adobe Creative Suite",
"doc_count": 1
},
{
"key": "Sales force",
"doc_count": 1
}
]
}
}
}
Here I searched for keyword Sales in field skills and I got matched documents. You can see one matched sample below:
"skills": [
"Account Management",
"Sales force",
"Adobe Creative Suite"
],
But I dont want "Account Management" and "Adobe Creative Suite" in query results as well in query aggregations. See below aggregation results:
"buckets": [
{
"key": "Account Management",
"doc_count": 1
},
{
"key": "Adobe Creative Suite",
"doc_count": 1
},
{
"key": "Sales force",
"doc_count": 1
}
]
Same way I don't want above "key": "Account Management" and "key": "Adobe Creative Suite" in aggregation results as I searched only for Sales .
I got above highlighted texts because skills field in my document has all these three skills but I am interested only in searched keywords. Please help me if anyone has solution for this.