在路径下获取嵌套对象不是elasticsearch查询中的嵌套类型

Getting nested object under path is not of nested type in elasticsearch query

我在尝试查询嵌套字段时遇到此错误, 这个问题似乎在重复但几乎没有变化,在设置字段映射时我没有指定嵌套但创建了嵌套映射。现在,当我尝试使用 gremlin 查询 Neptune 全文搜索查询时,它正在运行,但是当我尝试进行本机查询时,它给出了此错误:

failed to create a query: [nested] nested object under path [predicates] is not of nested type

Elasticsearch 索引映射

{
  "amazon_neptune" : {
    "mappings" : {
      "properties" : {
        "aggregateId" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "document_type" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "entity_id" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "entity_type" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "predicates" : {
          "properties" : {
            "group_name" : {
              "properties" : {
                "value" : {
                  "type" : "text",
                  "analyzer" : "autocomplete_analyzer",
                  "search_analyzer" : "standard"
                }
              }
            },
            "question" : {
              "properties" : {
                "value" : {
                  "type" : "text",
                  "analyzer" : "questions_auto_complete_analyzer",
                  "search_analyzer" : "standard"
                }
              }
            },
            "suggestion" : {
              "properties" : {
                "value" : {
                  "type" : "text",
                  "analyzer" : "autocomplete_analyzer",
                  "search_analyzer" : "standard"
                }
              }
            },
            "type" : {
              "properties" : {
                "value" : {
                  "type" : "text",
                  "fields" : {
                    "keyword" : {
                      "type" : "keyword",
                      "ignore_above" : 256
                    }
                  }
                }
              }
            },
            "user_name" : {
              "properties" : {
                "value" : {
                  "type" : "text",
                  "analyzer" : "autocomplete_analyzer",
                  "search_analyzer" : "standard"
                }
              }
            }
          }
        }
      }
    }
  }
}

正在运行的 gremlin 查询

g.withSideEffect('Neptune#fts.endpoint',ES Endpoint).withSideEffect('Neptune#fts.queryType', 'match').V().has('suggestion','Neptune#fts life').limit(5).valueMap().toList()

Elasticsearch 查询给出错误:

{
    "query": {
        "bool": {
            "must": [
                {
                    "term": {
                        "entity_type": "suggestions"
                    }
                },
                {
                    "term": {
                        "document_type": "vertex"
                    }
                },
                {
                    "nested": {
                        "path": "predicates",
                        "query": {
                            "nested": {
                                "path": "predicates.suggestion",
                                "query": {
                                    "match": {
                                        "predicates.suggestion.value": "life"
                                    }
                                }
                            }
                        }
                    }
                }
            ]
        }
    }
}

如果此查询有任何问题,请告诉我。

I didn't specify nested but created nested mapping

这就是问题所在。如果您没有明确指定 "type": "nested",那么 predicates 将不是 nested 类型,而是 object 类型,您的查询将无法正常工作见。

您需要在映射中将 predicates 显式定义为 nested,没有其他方法。

更新

您的本机查询应如下所示:

{
    "query": {
        "bool": {
            "must": [
                {
                    "term": {
                        "entity_type": "suggestions"
                    }
                },
                {
                    "term": {
                        "document_type": "vertex"
                    }
                },
                {
                    "match": {
                        "predicates.suggestion.value": "life"
                    }
                }
            ]
        }
    }
}

添加具有索引数据、映射、搜索查询和搜索结果的工作示例

索引映射:

{
  "mappings":{
    "properties":{
      "predicates":{
        "type":"nested",
        "properties":{
          "suggestion":{
            "type":"nested",
            "properties":{
              "value":{
                "type":"text"
              }
            }
          }
        }
      }
    }
  }
}

索引数据:

 {
      "predicates": [
        {
          "suggestion": [
            {
              "value": "life"
            }
          ]
        }
      ]
    }

运行 相同的搜索查询,如问题中给出的:

搜索结果:

"hits": [
      {
        "_index": "stof_64312693",
        "_type": "_doc",
        "_id": "1",
        "_score": 0.2876821,
        "_source": {
          "predicates": [
            {
              "suggestion": [
                {
                  "value": "life"
                }
              ]
            }
          ]
        }
      }
    ]