【问题标题】:Elasticsearch get data where field not null / field is null or field exist / field not existElasticsearch获取字段不为空/字段为空或字段存在/字段不存在的数据
【发布时间】:2016-06-26 16:32:09
【问题描述】:

我正在使用弹性搜索弹簧数据,我想添加过滤器,我可以按字段存在/字段不存在或字段值为空/不为空进行搜索。我该怎么做?

我知道我应该使用这样的东西:

{
  "query": {
    "filtered": {
      "filter": {
        "bool": {
          "must": [
            {
              "exists": {
                "field": "price"
              }
            },
            ...     <-- your other constraints, if any
          ]
        }
      }
    }
  }
}

如何在elasticsearch spring data中实现呢?

Optional.ofNullable(searchParams.getUid()).ifPresent(v -> filters.add(boolFilter().must(???????));

【问题讨论】:

    标签: java elasticsearch spring-boot spring-data spring-data-elasticsearch


    【解决方案1】:

    您可能想使用org.elasticsearch.index.query.FilterBuilders 来构建您的exists 过滤器

    FilterBuilders.boolFilter().must(FilterBuilders.existsFilter("price"))
    

    【讨论】:

      猜你喜欢
      • 2017-12-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多