查询嵌套字段时,Elasticsearch返回错误

时间:2019-11-13 13:10:33

标签: elasticsearch

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

{
"_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
              }
            }
          }
        }
      }
    }
  }
}

知道为什么会发生吗?

1 个答案:

答案 0 :(得分:1)

字段data是一个对象,因此其类型应为嵌套

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

希望有帮助

相关问题