具有嵌套字段问题的Elasticsearch 6.1多索引搜索

时间:2018-01-03 18:44:43

标签: elasticsearch

我使用嵌套字段

在2个索引中运行多索引搜索(elasticsearch 6.1.1)

" UNIQUEID"是一个仅存在于person索引中的嵌套字段。

" POBOX"是一个仅存在于地址索引

中的嵌套字段

我收到错误:

" index":"地址"," [嵌套]无法在路径[uniqueID]"

下找到嵌套对象

" index":" person"," [嵌套]路径[pobox]下的嵌套对象不是嵌套类型"

在我的查询中,我搜索字段uniqueID的人员索引,为什么我收到仅存在于地址索引中的pobox字段的错误。对于在地址索引中搜索,它会查找仅存在于人员索引

中的uniqueId字段

POST http://locahost:9200/person,adress/_search



{
  "query": {
    "bool": {
      "should": [
        {
          "bool": {
            "must": [
              {
                "terms": {
                  "_index": [
                    "person"
                  ]
                }
              },
              {
                "nested": {
                  "path": "uniqueID",
                  "query": {
                    "span_near": {
                      "clauses": [
                        {
                          "span_term": {
                            "uniqueID.uniqueID.auto": "1"
                          }
                        }
                      ],
                      "slop": 3,
                      "in_order": true
                    }
                  }
                }
              }
            ]
          }
        },
        {
          "bool": {
            "must": [
              {
                "terms": {
                  "_index": [
                    "adress"
                  ]
                }
              },
              {
                "nested": {
                  "path": "pobox",
                  "query": {
                    "span_near": {
                      "clauses": [
                        {
                          "span_term": {
                            "pobox.pobox.auto": "1"
                          }
                        }
                      ],
                      "slop": 3,
                      "in_order": true
                    }
                  }
                }
              }
            ]
          }
        }
      ]
    }
  }
}




错误



{
    "error": {
        "root_cause": [
            {
                "type": "query_shard_exception",
                "reason": "failed to create query: { my_query }",
                "index_uuid": "9Z0W-P9ZS02kJ7WmOKHPVQ",
                "index": "adress"
            },
            {
                "type": "query_shard_exception",
                "reason": "failed to create query: { my_query }",
                "index_uuid": "EHoxKGhdSmKoYdNgsylotw",
                "index": "person"
            }
        ],
        "type": "search_phase_execution_exception",
        "reason": "all shards failed",
        "phase": "query",
        "grouped": true,
        "failed_shards": [
            {
                "shard": 0,
                "index": "adress",
                "node": "AEhiq0wvQTGh468sSmDN5g",
                "reason": {
                    "type": "query_shard_exception",
                    "reason": "failed to create query: { my_query }",
                    "index_uuid": "9Z0W-P9ZS02kJ7WmOKHPVQ",
                    "index": "adress",
                    "caused_by": {
                        "type": "illegal_state_exception",
                        "reason": "[nested] failed to find nested object under path [uniqueID]"
                    }
                }
            },
            {
                "shard": 0,
                "index": "person",
                "node": "AEhiq0wvQTGh468sSmDN5g",
                "reason": {
                    "type": "query_shard_exception",
                    "reason": "failed to create query: { my_query }",
                    "index_uuid": "EHoxKGhdSmKoYdNgsylotw",
                    "index": "person",
                    "caused_by": {
                        "type": "illegal_state_exception",
                        "reason": "[nested] nested object under path [pobox] is not of nested type"
                    }
                }
            }
        ]
    },
    "status": 400
}




1 个答案:

答案 0 :(得分:1)

好吧,你尝试在一个索引上查询的嵌套结构在另一个索引上不存在,那么你期望什么呢?

IMO你应该分开查询并使用_msearch如果你总是需要这些查询。