gpt4 book ai didi

Elasticsearch:路径下的嵌套对象不是嵌套类型

转载 作者:行者123 更新时间:2023-11-29 02:43:35 25 4
gpt4 key购买 nike

我一直在尝试搜索包含嵌套字段的文档。我创建了这样的嵌套映射:

{
"message": {
"properties": {
"messages": {
"type": "nested",
"properties": {
"message_id": { "type": "string" },
"message_text": { "type": "string" },
"message_nick": { "type": "string" }
}
}
}
}
}

我的搜索是这样的:

curl -XGET 'localhost:9200/thread_and_messages/thread/_search' \
-d '{"query": {"bool": {"must": [{"match": {"thread_name": "Banana"}}, {"nested": {"path": "messages", "query": {"bool": {"must": [{"match": {"messages.message_text": "Banana"}}]}}}]}}}}'

但我收到此错误消息:

QueryParsingException[[thread_and_messages] [nested] nested object under path [messages] is not of nested type]

编辑

我仍然收到此错误。我通过 Java 执行此操作,因此这是我要创建的文档:

{
"_id": {
"path": "3",
"thread_id": "3",
"thread_name": "Banana",
"created": "Wed Mar 25 2015",
"first_nick": "AdminTech",
"messages": [
{
"message_id": "9",
"message_text": "Banana",
"message_nick": "AdminTech"
}
]
}
}

像这样创建索引:

CreateIndexRequestBuilder indexRequest = client.admin().indices().prepareCreate(INDEX).addMapping("message", mapping);

我想我可能没有正确地索引文档。

最佳答案

TLDR:将 "type": "nested", 放入您的嵌套类型中。

假设我们有一个普通类型,另一个类型嵌套在其中:

{
"some_index": {
"mappings": {
"normal_type": {
"properties": {
"nested_type": {
"type": "nested",
"properties": {
"address": {
"type": "string"
},
"country": {
"type": "string"
}
}
},
"first_name": {
"type": "string"
},
"last_name": {
"type": "string"
}
}
}
}
}
}

"type": "nested", 行是嵌套查询工作所必需的,其中 "path": 分配给 nested_type,像这样:

GET /some_index/normal_type/_search
{
"query": {
"nested": {
"query": {
"bool": {}
},
"path": "nested_type"
}
}
}

"type": "nested", 行似乎只在较新的 Elasticsearch 版本中是必需的(从 1.1.1 开始?)。

关于Elasticsearch:路径下的嵌套对象不是嵌套类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29346935/

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