3country

Java 如何获取聚合查询后 top_hits 中的_source 值?求大佬解答

  •  
  •   3country · Jun 30, 2020 · 4803 views
    This topic created in 2167 days ago, the information mentioned may be changed or developed.

    刚学习 es,这个问题困扰了我很久。。求大佬救救我 查询语句

    {
      "query": {
        "term": {
          "memberid": "2136476"
        }
      },
      "aggs": {
        "group": {
          "terms": {
            "field": "meetingid",
            "order": {
              "addtime": "desc"
            }
          },
          "aggs": {
            "result": {
              "top_hits": {
                "_source": [
                  "meetingid",
                  "memo",
                  "addtime"
                ],
                "size": 1,
                "sort": {
                  "addtime": {
                    "order": "desc"
                  }
                }
              }
            },
            "addtime": {
              "max": {
                "field": "addtime"
              }
            }
          }
        }
      }
    }
    

    我想要获取_source 的值

    最后获取到这一步后卡住了,debug 了一下发现有一个 SearchHit 的值,但我用 getProperty()获取不到,求解答

    		SearchResponse response = client.search(request).actionGet();
            Aggregations aggregations = response.getAggregations();
            Aggregation a = aggregations.get("meeting");
            Terms teamSum= (Terms)a;
            for(Terms.Bucket bucket:teamSum.getBuckets()){
                Aggregation aggregation = bucket.getAggregations().get("result");
            }
    
    Supplement 1  ·  Jun 30, 2020
    已解决。。。
    看来我使用搜索引擎的姿势不对,昨天搜了一下午没找到解决方法
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2800 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 10:06 · PVG 18:06 · LAX 03:06 · JFK 06:06
    ♥ Do have faith in what you're doing.