情況:彈性同義詞使用
使用彈性版本:2.3.1
我已經配置像這樣
PUT /my_index
{
"settings": {
"analysis": {
"filter": {
"my_synonym_filter": {
"type": "synonym",
"synonyms": [
"british,english",
"queen,monarch"
]
}
},
"analyzer": {
"my_synonyms": {
"tokenizer": "standard",
"filter": [
"lowercase",
"my_synonym_filter"
]
}
}
}
}
}
,這是偉大的彈性指數,當我查詢文件和使用查詢字詞「英文」或「女王」我得到所有文件匹配英國和君主。當我在過濾器聚合中使用同義詞時,它不起作用。例如
在我的索引我有5個文件,其中3個有君主,其中2個有女王
POST /my_index/_search
{
"size": 0,
"query" : {
"match" : {
"status.synonym":{
"query": "queen",
"operator": "and"
}
}
},
"aggs" : {
"status_terms" : {
"terms" : { "field" : "status.synonym" }
},
"monarch_filter" : {
"filter" : { "term": { "status.synonym": "monarch" } }
}
},
"explain" : 0
}
結果產生:
總共點擊:
- 5 doc count(如預期的那樣,太棒了!)
- 狀態條件:5個文件數爲女王(如預期的那樣,太棒了!)
- 君主濾波器:0 DOC計數
我已經嘗試了不同的同義詞濾波器配置:
- 王后,闢
- 王后,闢=>王后
- 王后,闢=>女王,君主
但是,上述並沒有改變結果。我想得出結論,也許你可以在查詢時使用過濾器,但如果術語聚合工作,爲什麼不應該過濾,因此我認爲它的同義詞過濾器配置是錯誤的。更廣泛的同義詞過濾器示例可以在here找到。
問題:
如何使用/配置過濾器聚集同義詞?
實施例中複製的情況下,上述: 1.創建和配置索引:
PUT /my_index
{
"settings": {
"analysis": {
"filter": {
"my_synonym_filter": {
"type": "synonym",
"synonyms": [
"wlh,wellhead=>wellwell"
]
}
},
"analyzer": {
"my_synonyms": {
"tokenizer": "standard",
"filter": [
"lowercase",
"my_synonym_filter"
]
}
}
}
}
}
PUT my_index/_mapping/job
{
"properties": {
"title":{
"type": "string",
"analyzer": "my_synonyms"
}
}
}
2.Put兩個文件:
PUT my_index/job/1
{
"title":"wellhead smth else"
}
PUT my_index/job/2
{
"title":"wlh other stuff"
}
3。執行wlh的搜索,它應該返回2個文檔;有哪些不應該有0計數方面聚集了應有的2個文件wellwell和過濾器:
POST my_index/_search
{
"size": 0,
"query" : {
"match" : {
"title":{
"query": "wlh",
"operator": "and"
}
}
},
"aggs" : {
"wlhAggs" : {
"terms" : { "field" : "title" }
},
"wlhFilter" : {
"filter" : { "term": { "title": "wlh" } }
}
},
"explain" : 0
}
此查詢的結果是:
{
"took": 8,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 0,
"hits": []
},
"aggregations": {
"wlhAggs": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "wellwell",
"doc_count": 2
},
{
"key": "else",
"doc_count": 1
},
{
"key": "other",
"doc_count": 1
},
{
"key": "smth",
"doc_count": 1
},
{
"key": "stuff",
"doc_count": 1
}
]
},
"wlhFilter": {
"doc_count": 0
}
}
}
並且那是我的問題, wlhFilter應該至少有1個文檔數。
很好,你明白了! –
我在同一時間發佈更新。甚至找到了更好的解決方案。謝謝你的幫助 –