【问题标题】:Elasticsearch return error when querying a nested field查询嵌套字段时 Elasticsearch 返回错误
【发布时间】:2019-11-13 22:25:55
【问题描述】:

我在弹性搜索中有一些索引数据,我正在尝试使用邮递员通过以下请求获取数据。

{
"_source": ["_id"],
"query":  {
    "nested" : {
        "path" : "data",
        "query" : {
            "bool" : {
                "must" : [
                { "match" : {"data.id": "3456"} }
                ]
            }
        },
        "score_mode" : "avg"
    }
}

}

但我遇到了异常

[nested] nested object under path [data] is not of nested type

我的映射定义是这样的

    {
  "property": {
    "mappings": {
      "property": {
        "properties": {
          "data": {
            "properties": {
              "id": {
                "type": "text",
                "fields": {
                  "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              }
            }
          },
          "point": {
            "properties": {
              "lat": {
                "type": "float"
              },
              "lon": {
                "type": "float"
              }
            }
          },
          "popId": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          }
        }
      }
    }
  }
}

知道为什么会这样吗?

【问题讨论】:

  • 请分享您的映射定义
  • @AssaelAzran 添加了映射定义。
  • 你的弹性版本是什么?您的映射中的 destinations 嵌套对象在哪里?
  • 版本为 6.7.0
  • Robin 请添加真实映射的复制粘贴(来自 GET /_mapping 。您添加的内容似乎是“手写”映射。另外:您肯定没有添加正确的查询你的问题,因为当你的查询没有提到它时,错误提到了一个“目标”路径。

标签: elasticsearch


【解决方案1】:

字段data 是一个对象,所以它的类型应该是nested

Nested Type

试试这些映射配置:

PUT property
{
  "mappings": {
    "property": {
      "properties": {
        "point": {
          "properties": {
            "lat": {
              "type": "float"
            },
            "lon": {
              "type": "float"
            }
          }
        },
        "popId": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "data": {
          "type": "nested",
          "properties": {
            "id": {
              "type": "text",
              "fields": {
                "keyword": {
                  "type": "keyword",
                  "ignore_above": 256
                }
              }
            }
          }
        }
      }
    }
  }
}

您必须删除索引并使用新的映射配置重新创建它。

如果您不想删除数据,可以help

希望对你有帮助

【讨论】:

    猜你喜欢
    • 2021-11-10
    • 2019-12-20
    • 1970-01-01
    • 1970-01-01
    • 2019-07-08
    • 1970-01-01
    • 2021-07-13
    • 1970-01-01
    • 2020-09-04
    相关资源
    最近更新 更多