【问题标题】:Search in multiple index , 'query_shard_exception' when fields are not present在多个索引中搜索,当字段不存在时,'query_shard_exception'
【发布时间】:2018-11-12 16:10:08
【问题描述】:

我正在尝试在多个索引中进行搜索,但每个索引的字段和映射都不同。就像一个索引有嵌套路径一样。

当我尝试查询索引时,我收到了没有嵌套路径的索引的错误。

    {
  "query": {
    "bool": {
      "should": [
        {
          "term": {
            "a": "good"
          }
        },
        {
          "term": {
            "a.b": "sample"
          }
        },
        {
          "nested": {
            "path": "x.y.z",
            "query": {
              "bool": {
                "should": [
                  {
                    "term": {
                      "x.y.z.id.keyword": "test@gamil.com"
                    }
                  }
                ]
              }
            }
          }
        }
      ]
    }
  }
}

在上面的嵌套路径 x.y.z 只存在于一个索引。

我尝试寻找解决方案,找到了ignore_unavailable。但它会忽略没有嵌套路径的索引,但我需要该索引中的文档与查询中的其他条件匹配。

【问题讨论】:

    标签: elasticsearch elasticsearch-5


    【解决方案1】:

    尝试以下查询,将your-index 替换为包含嵌套字段的索引名称。

    {
      "query": {
        "bool": {
          "should": [
            {
              "term": {
                "a": "good"
              }
            },
            {
              "term": {
                "a.b": "sample"
              }
            },
            {
              "bool": {
                "must": [
                  {
                    "term": {
                      "_index": "your-index"
                    }
                  },
                  {
                    "nested": {
                      "path": "x.y.z",
                      "query": {
                        "bool": {
                          "should": [
                            {
                              "term": {
                                "x.y.z.id.keyword": "test@gamil.com"
                              }
                            }
                          ]
                        }
                      }
                    }
                  }
                ]
              }
            }
          ]
        }
      }
    }
    

    【讨论】:

    • 仍然收到[nested] failed to find nested object under path
    • 你能分享你的映射吗?
    • { nested: { path: "a/b/c", ignore_unmapped: true, query: { bool: { should: [] } } } 可以通过添加ignore_unmapped: true解决问题
    猜你喜欢
    • 2012-02-12
    • 2012-03-11
    • 1970-01-01
    • 1970-01-01
    • 2018-08-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-06
    • 1970-01-01
    相关资源
    最近更新 更多