Elastic Search - QueryBuilder JAVA

I'm currently working on elasticsearch where I've created a query :

"query": {

    "bool": {
      "must": [
        {"match": {
          "companyId": 35
        }},
        {
          "multi_match": {
            "query": "movie",
            "fields": ["name", "description"]
          }
        }
      ]
    }
  }
}

For which I have build QueryBuilder in JAVA :

        SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();

                
        QueryBuilder mulMatch = QueryBuilders.multiMatchQuery(name,"name", "description").type("phrase").boost(5);
        QueryBuilder cId = QueryBuilders.matchQuery("companyId", companyId).boost(5);
        QueryBuilder must = QueryBuilders.boolQuery().must(cId).must(mulMatch).boost(5);
        
        searchSourceBuilder.query(must);
        searchRequest.source(searchSourceBuilder);
        System.out.println("SS Query : " + searchSourceBuilder);

which gives me query created as :

{"query":{"bool":{"must":[{"match":{"companyId":{"query":35,"operator":"OR","prefix_length":0,"max_expansions":50,"fuzzy_transpositions":true,"lenient":false,"zero_terms_query":"NONE","auto_generate_synonyms_phrase_query":true,"boost":5.0}}},{"multi_match":{"query":"movie","fields":["description^1.0","name^1.0"],"type":"phrase","operator":"OR","slop":0,"prefix_length":0,"max_expansions":50,"zero_terms_query":"NONE","auto_generate_synonyms_phrase_query":true,"fuzzy_transpositions":true,"boost":5.0}}],"adjust_pure_negative":true,"boost":5.0}}}

However, I require output such as :

{

          "Id": 1,
          "name": "Controle",
          "description": "Welcome movie",
          "visibility": "2",
          "isarticleEnabled": false,
          "companyId": 35,
          "categoryId": 0        
}

So to get such a a response, what should I exactly do? What do I need to write in queryBuilder to get the required output?

Note: I've searched for all the relative solutions, i.e. Search Request, Search Response, but I was unable to get any of the proper solutions.

Hi @Parva_Gurav

The query not works?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.