0

我正在创建一个 java spring 示例以从弹性搜索中获取结果。我想在 java 示例中运行以下感知查询 -

GET /_all/explore/_search?search_type=count
{
  "aggs": {
    "metaDatas": {
      "terms": {
        "field": "metaData",
        "size": 1000
      }
    }
  }
} 

为此,我尝试了-

 String query = "{\n"

                + " \"aggs\": {\n"
                + " \"metaDatas\": {\n"
                + " \"terms\": {\n"
                + " \"field\": \"metaData\",\n"
                + "  \"size\": 1000\n"
        +"}\n"
                +"}\n"
                +"}\n"
                +"}\n";
        QueryStringQueryBuilder queryBuilder = new QueryStringQueryBuilder('"' + query + '"');
        SearchRequestBuilder requestBuilder = client.prepareSearch()
                .setTypes("explore")
                .setScroll(new TimeValue(ES_TIMEOUT_MS))
                .setQuery(queryBuilder);
        requestBuilder.setFrom(0);
        requestBuilder.setSize(DEFAULT_SEARCH_PAGE_SIZE);
        SearchResponse response = requestBuilder.execute().actionGet(ES_TIMEOUT_MS);
        SearchHits hits = response.getHits();

但它给出了 0 次点击。从某种意义上说,它给出了以下结果 -

{
   "took": 32,
   "timed_out": false,
   "_shards": {
      "total": 78,
      "successful": 78,
      "failed": 0
   },
   "hits": {
      "total": 535,
      "max_score": 0,
      "hits": []
   },
   "aggregations": {
      "metaDatas": {
         "doc_count_error_upper_bound": 0,
         "sum_other_doc_count": 0,
         "buckets": [
            {
               "key": "textplain",
               "doc_count": 229
            },
            {
               "key": "applicationxml",
               "doc_count": 162
            },
            {
               "key": "imagejpeg",
               "doc_count": 22
            },
            {
               "key": "textxwebmarkdown",
               "doc_count": 18
            },
            {
               "key": "textxjavaproperties",
               "doc_count": 13
            }
         ]
      }
   }
}

我怎样才能在java中得到这个结果。

4

0 回答 0