boost in neural query in opensearch using javaclient

110 views Asked by At

In open search I have alias called product_alias this alias has two indexes first_party_products and third_party_products

Now I want to do query within in the alias and want to boost the first_party_products

When I run the following code in opensearch console it works fine. But from codebase it is not working

GET /products_alias/_search
{
  "from": 0,
  "size": 3, 
  "indices_boost": [
     { "first_party_products": 1.01}
  ],
  "query": {
    "bool": {
      "should": [
        {
          "script_score": {
            "query": {
              "neural": {
                "description_vector": {
                  "query_text": "starbucks",
                  "model_id": "-w8uWee5kd",
                  "k": 5
                }
              }
            },
            "script": {
              "source": "_score * 1"
            }
          }
        }
      ]
    }
  }
}

In java we are using this client https://github.com/opensearch-project/opensearch-java

and following is the codebase I have put

            
           NeuralQuery neuralQuery = new NeuralQuery.Builder()
                    .field(embeddingMapping)
                    .queryText(param.getQuery())
                    .modelId(MODEL_ID)
                    .k(KNN_TOP_K)
                    .build();
            
            Query query = new Query.Builder()
                    .neural(neuralQuery)
                    .build();
            


            List<Map<String, Double>> indicesBoost = new ArrayList<>();
            Map<String, Double> indicesBoostMap = new HashMap<>();
            indicesBoostMap.put(SearchCategory.FIRST_PARTY_PRODUCTS.getIndexName(), 1.01);
            indicesBoost.add(indicesBoostMap);


            var searchResponse = openSearchJavaClient.search(
                    s -> s.index(semanticIndex)
                            .from(param.getOffset())
                            .size(param.getLimit())
                            .indicesBoost(indicesBoost)
                            .sort(sortOptions)
                            .query(query)
                            .source(sourceConfig)
                    , Object.class
            );

Is there anything I have missed out.

Thanks in advance

I want to boost the index of a neural query depending on the indicies

0

There are 0 answers