簡體   English   中英

在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"
                }
              }
            }
          }
        }
      }
    }
  }
}

正在工作的小鬼查詢

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"
                                    }
                                }
                            }
                        }
                    }
                }
            ]
        }
    }
}

如果此查詢有任何問題,請告訴我。

我沒有指定嵌套但創建了嵌套映射

這就是問題所在。 如果您沒有明確指定"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"
                }
              ]
            }
          ]
        }
      }
    ]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM