开发者

Building a bool query with Spring Data Elasticsearch

开发者 https://www.devze.com 2022-12-07 17:23 出处:网络
I\'m trying to make a bool must match query in java with this structure GET offers/_search { "query": {

I'm trying to make a bool must match query in java with this structure

GET offers/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "offerLine": "Technology"
          }
        }
      ]
    }
  }
}

I've tried this and I'm getting a null value:

private NativeQueryBuilder prepareElasticQuery(OfferRequest开发者_StackOverflow request){
    BoolQuery.Builder bqb = QueryBuilders.bool();
    bqb.must(m->m.match(ma->ma.field("offerLine").query(request.getOfferLine())));
    NativeQueryBuilder nqb= new NativeQueryBuilder().withQuery(bqb.build()._toQuery());
    return nqb;
}

The bool query gets this value :

BoolQuery: {"must":[{"match":{"offerLine":{"query":"Technology"}}}]}

And I can't seem to find an alternative to the value() method since it's deprecation. Any clues as to how I can build it properly?

Edit: That's the proper way. My problem is with further handling the results.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号