gpt4 book ai didi

Elasticsearch - multi_match 不适用于嵌套字段

转载 作者:行者123 更新时间:2023-12-02 22:18:55 25 4
gpt4 key购买 nike

我的记录可以对单个文本字段进行多种翻译,例如:

{
"type": "movie",
"title": {
"en": "Dark Knight",
"de": "Der dunkle Ritter"
}
}

为了表示这些记录,我创建了以下索引:

{
"mappings": {
"_doc": {
"properties": {
"type": {
"type": "text",
"analyzer": "english"
},
"title": {
"type": "nested",
"properties": {
"de": {
"type": "text",
"analyzer": "german"
},
"en": {
"type": "text",
"analyzer": "english"
}
}
}
}
}
}
}

但是当我尝试使用 multi_map查询它不返回预期的结果。此查询查找记录(按顶级 type 字段搜索):

{
"query": {
"multi_match" : {
"query" : "movie"
}
}
}

但是这个查询没有(通过嵌套的 title.en 字段搜索):

{
"query": {
"multi_match" : {
"query": "dark"
}
}
}

这很令人惊讶,因为如果我得到 title.en 的术语向量字段似乎记录被正确索引:

GET /test_with_lang/_doc/1/_termvectors?pretty=true&fields=*

{
"_index": "test_with_lang",
"_type": "_doc",
"_id": "1",
"_version": 1,
"found": true,
"took": 1,
"term_vectors": {
"title.en": {
"field_statistics": {
"sum_doc_freq": 2,
"doc_count": 1,
"sum_ttf": 2
},
"terms": {
"dark": {
"term_freq": 1,
"tokens": [
{
"position": 0,
"start_offset": 0,
"end_offset": 4
}
]
},
"knight": {
"term_freq": 1,
"tokens": [
{
"position": 1,
"start_offset": 5,
"end_offset": 11
}
]
}
}
}
}
}

查询似乎也使用了正确的字段,它应该匹配其中一个标记:

Request:
GET /test_with_lang/_doc/1/_explain
{
"query": {
"multi_match" : {
"query": "dark"
}
}
}


Reply:
{
"_index": "test_with_lang",
"_type": "_doc",
"_id": "1",
"matched": false,
"explanation": {
"value": 0.0,
"description": "Failure to meet condition(s) of required/prohibited clause(s)",
"details": [
{
"value": 0.0,
"description": "no match on required clause ((type:dark | title.en:dark | title.de:dark))",
"details": [
{
"value": 0.0,
"description": "No matching clause",
"details": []
}
]
},
...
]
}
]
}
}

注意它正在寻找 token dark在现场title.en (no match on required clause ((type:dark | title.en:dark | title.de:dark)))。

我正在使用 Elasticsearch 6.2.1

看起来查询应该有效。我错过了什么吗?

最佳答案

嵌套字段需要特殊的嵌套查询:

"query": {
"nested": {
"path": "title",
"query": {
"multi_match": {
"query": "dark"
}
}
}
}

但我怀疑嵌套字段在您的情况下是否必要。只需为 title 字段使用常规对象类型,就可以通过简单的 multi_match 查询在所有文档字段中进行查找。

关于Elasticsearch - multi_match 不适用于嵌套字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48832628/

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