gpt4 book ai didi

elasticsearch - Elasticsearch multi_match查询不适用于同义词和cross_fields

转载 作者:行者123 更新时间:2023-12-02 23:24:10 25 4
gpt4 key购买 nike

带有cross_fiels类型和同义词的Elasticsearch多匹配查询无法正常工作。

我有以下配置:

{
"my_index": {
"mappings": {
"my_mapping": {
"properties": {
"@timestamp": {
"type": "date"
},
"@version": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"field1": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"field2": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
},
"settings": {
"index": {
"analysis": {
"filter": {
"my_synonym_filter": {
"type": "synonym",
"synonyms": [
"matthew,matt,matty",
"thomas,tom,thom,tommy"
]
}
},
"analyzer": {
"my_synonyms": {
"filter": [
"lowercase",
"my_synonym_filter"
],
"tokenizer": "standard"
}
}
}
}
}
}
}

和以下查询:
{
"query":{
"bool":{
"should":[
{
"multi_match":{
"fields":[
"field1^8",
"field2^2"
],
"query":"Matt And Tom Oldfield",
"type":"cross_fields",
"analyzer": "my_synonyms"
}
}
]
}
}
}

但是,当我执行查询时,它并没有将同义词扩展到每个字段中,因此,如果我分析查询,说明如下:
(Synonym(field1:matt field1:matthew field1:matty) blended(terms:[field1:and^8.0, field2:and^2.0]) Synonym(field1:thom field1:thomas field1:tom field1:tommy) blended(terms:[field1:oldfield^8.0, field2:oldfield^2.0]))
因此,如果我在field1中具有“Tom Oldfield”而在field2中具有“Matt Oldfield”,则该查询与该结果不匹配,因为您可以看到它仅扩展了同义词,但扩展了第一个字段( field1),而没有扩展其他字段。

如果我从查询中删除分析器,则它将使文档与field1中的“Tom Oldfield”和field2中的“Matt Oldfield”匹配,查询说明如下:
(blended(terms:[field1:matt^8.0, field2:matt^2.0]) blended(terms:[field1:and^8.0, field2:and^2.0]) blended(terms:[field1:tom^8.0, field2:tom^2.0]) blended(terms:[field1:oldfield^8.0, field2:oldfield^2.0]))
有没有办法使同义词扩展到每个 Realm ?

最佳答案

我无法在 flex 5.5.0的环境中重现您的问题。
这是我的MVCE设置:

{
"settings": {
"index": {
"analysis": {
"filter": {
"my_synonym_filter": {
"type": "synonym",
"synonyms": [
"matthew,matt,matty",
"thomas,tom,thom,tommy"
]
}
},
"analyzer": {
"my_synonyms": {
"filter": [
"lowercase",
"my_synonym_filter"
],
"tokenizer": "standard"
}
}
}
}
},
"mappings": {
"my_mapping": {
"properties": {
"field1": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"field2": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}

已将以下文档编入索引:
{ "field1": "Tom Oldfield", "field2": "Matt Oldfield"}

在提供的查询中,ES创建以下 Lucene query
((field1:matt)^8.0 | (field1:matthew)^8.0 | (field1:matty)^8.0 | (field2:matt)^2.0 | (field2:matthew)^2.0 | (field2:matty)^2.0) 
((field1:and)^8.0 | (field2:and)^2.0)
((field1:tom)^8.0 | (field1:thomas)^8.0 | (field1:thom)^8.0 | (field1:tommy)^8.0 | (field2:tom)^2.0 | (field2:thomas)^2.0 | (field2:thom)^2.0 | (field2:tommy)^2.0)
((field1:oldfield)^8.0 | (field2:oldfield)^2.0))

其中每个字段都扩展了同义词。

关于elasticsearch - Elasticsearch multi_match查询不适用于同义词和cross_fields,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45148041/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com