具有不同属性的弹性搜索多索引搜索

时间:2015-12-22 11:39:19

标签: elasticsearch

使用多索引查询查询时遇到问题。我有多个具有不同属性的索引。我想要一个查询,它返回所有索引的结果,并仅在存在一个属性时过滤结果。

目前如果属性不存在,则不会返回该索引的响应。

示例:

FirstIndex {
    attribute: {
         type: type1
         flag: false
    }
}

SecondIndex{
    attribute: {
         type: type1
   }
}

以上标记attribute:flag不存在,因此如果搜索位于flag=false,则应返回匹配以及secondIndex。像dbms中的外连接一样。

1 个答案:

答案 0 :(得分:0)

可能您可以尝试使用以下查询:

{
  "query": {
    "filtered": {
      "filter": {
        "bool": {
          "should": [
            {
              "exists": {
                "field": "user"
              }
            },
            {
              "missing": {
                "field": "user"
              }
            }
          ]
        }
      }
    }
  }
}

在字段列中添加所需字段。

相关问题