【问题标题】:How to convert ElasticSearch query to java如何将 ElasticSearch 查询转换为 java
【发布时间】:2020-02-07 20:15:40
【问题描述】:

我正在使用弹性搜索 7.5,如何将以下查询转换为 java 以及如何从响应中获取聚合结果。

curl -XGET --header 'Content-Type: application/json'  http://localhost:9200/product/_search?pretty -d '
{  
"size": 0,
  "aggs": {
    "specs": {
      "nested": {
        "path": "specs"
      },
      "aggs": {
        "specList": {
          "terms": {
            "field": "specs.value",
            "size": 100
          }
        }
      }
    }
  }
}'

【问题讨论】:

标签: elasticsearch


【解决方案1】:

使用 java Rest 客户端 API 为您的查询构建聚合:

AggregationBuilder aggregationBuilder = AggregationBuilders
                .nested("specs","specs")
                .subAggregation(
                        AggregationBuilders.terms("specList").field("specs.value").size(100)
                );

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2018-04-07
  • 1970-01-01
  • 1970-01-01
  • 2018-09-17
  • 2019-11-22
  • 1970-01-01
  • 2018-10-23
  • 1970-01-01
相关资源
最近更新 更多