繁体   English   中英

在过滤器查询结果中保留缺少字段的文档

[英]Keep the documents with a missing field in the filter query results

我正在使用以下查询查询索引:

GET /dbpedia201510/entity/_search
{
    "from": 0,
    "size": 10000,
    "query": {
        "bool": {
            "must": {
                "query_string":{
                    "fields": ["name","alias","pseudonyme"],
                    "query": "Elias~ Franck~",
                    "default_operator": "OR",
                    "fuzziness": "auto"
                }
            },
            "filter": {
                "bool": {
                    "must": [
                        {
                            "terms": {
                                "job.keyword":["Architect","Politician","Tailor"]
                            }
                        }
                    ]
                }
            }
        }
    }
}

job字段是一个字符串数组,查询的工作方式与预期的一样。 但是,有些文档没有job字段,我也想获取这些文档。

我怎样才能做到这一点?

您需要在此处使用should clause ,该should clause在任何一个job字段存在且匹配术语查询 job字段不存在时匹配。

您的最终查询应如下所示:

GET /dbpedia201510/entity/_search
{
  "from": 0,
  "size": 10000,
  "query": {
    "bool": {
      "must": {
        "query_string": {
          "fields": ["name","alias","pseudonyme"],
          "query": "Elias~ Franck~",
          "default_operator": "OR",
          "fuzziness": "auto"
        }
      },
      "filter": {
        "bool": {
          "should": [
            {
              "terms": {
                "job.keyword": ["Architect","Politician","Tailor"]
              }
            },
            {
              "bool": {
                "must_not": {
                  "exists": {
                    "field": "job"
                  }
                }
              }
            }
          ]
        }
      }
    }
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM