情况:弹性同义词使用
使用弹性版本: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个文档数。
很好,你明白了! –
我在同一时间发布更新。甚至找到了更好的解决方案。谢谢你的帮助 –