在弹性搜索查询中获取路径下的嵌套对象不是嵌套类型

时间:2020-10-12 06:27:12

标签: elasticsearch gremlin amazon-neptune

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

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

请让我知道此查询是否有问题。

2 个答案:

答案 0 :(得分:2)

我没有指定嵌套,但是创建了嵌套映射

这就是问题所在。如果您未明确指定function openDriveFolder(){ var html = "<script>window.open('https://drive.google.com/drive/folders/1HPEQmmWo6ALNP4zw8FZCtu2C3zFYCdZs?usp=sharing');google.script.host.close();</script>"; var userInterface = HtmlService.createHtmlOutput(html); SpreadsheetApp.getUi().showModalDialog(userInterface, 'Open Womble Drive Folder'); } ,那么"type": "nested"的类型将不是predicates,而类型是nested,并且查询将无法正常工作见。

您需要在映射中将object明确定义为predicates,没有其他方法。

更新

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

nested

答案 1 :(得分:1)

添加包含索引数据,映射,搜索查询和搜索结果的工作示例

索引映射:

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