1
我的查詢:如何Elasticsearch聚集和源只返回匹配的文本太
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"
}
}
}
}
}
查詢結果:
{
"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
}
]
}
}
}
在這裏,我搜索了場技能關鍵字銷售和我匹配的文檔。您可以在下面看到一個匹配的樣品:
"skills": [
"Account Management",
"Sales force",
"Adobe Creative Suite"
],
但我不希望在查詢結果中「賬戶管理」和「Adobe Creative Suite的」,以及查詢聚合。見下面聚集的結果:
"buckets": [
{
"key": "Account Management",
"doc_count": 1
},
{
"key": "Adobe Creative Suite",
"doc_count": 1
},
{
"key": "Sales force",
"doc_count": 1
}
]
同樣我也不想上述「關鍵」:作爲我搜索只對聚集結果「Adobe Creative Suite的」:「帳戶管理」和「鍵」銷售*。
我上面有突出的文本,因爲我的文檔中的技能領域擁有所有這三個技能,但我感興趣的只是搜索的關鍵字。請幫助我,如果有人有這個解決方案。