【问题标题】:How find all documents in elasticsearch that matches with fields and values?如何在 elasticsearch 中找到与字段和值匹配的所有文档?
【发布时间】:2015-04-03 06:50:33
【问题描述】:

我有一个索引usersuser 类型。映射是动态的。现在 user 具有以下结构:

"user": {
        "nested": {
            "one":51
        },
        "other": {
            "two":"hi!"
        },
        "three":false
    }

我需要找到所有具有 other.two 字段且值为 hi 或具有 three 字段且值为 false 的用户。例如。具有other.two 的用户必须在其中具有hi 值或具有false 值的three 字段。如何从弹性搜索中选择这个?

我试过了:

GET /users/user/_search
{"query": {"match": {"other.two": "hi"}}}

为我返回一个用户,但是

GET /users/user/_search
    {"query": {"match": {"other.two": "hi", "three":false}}}

给我一​​个SearchPhaseExecutionException

如何组合多个字段和值进行搜索?

【问题讨论】:

    标签: search elasticsearch


    【解决方案1】:

    【讨论】:

      【解决方案2】:

      正如上面的@rvheddeg 建议的那样,这是对我有用的查询:

      {
      "query": {
          "bool": {
              "should": [
                      { "match": { "other.two":  "hi" }},
                      { "match": { "three": false  }}
                  ],
                  "minimum_should_match": 1
              }
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-02-12
        • 1970-01-01
        • 2020-05-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-11-18
        相关资源
        最近更新 更多