# Unable to find in Java Client API ES 8.7 replacement of fieldsAndWeights in QueryStringQueryBuilder of earlier version

**URL:** https://discuss.elastic.co/t/unable-to-find-in-java-client-api-es-8-7-replacement-of-fieldsandweights-in-querystringquerybuilder-of-earlier-version/336285
**Category:** Elasticsearch
**Tags:** language-clients
**Created:** [June 17, 2023, 7:17pm UTC](https://discuss.elastic.co/t/unable-to-find-in-java-client-api-es-8-7-replacement-of-fieldsandweights-in-querystringquerybuilder-of-earlier-version/336285 "2023-06-17T19:17:35Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![ramyogi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ramyogi/32/120207_2.png) [@ramyogi](https://discuss.elastic.co/u/ramyogi)
#### Post date: [June 17, 2023, 7:17pm UTC](https://discuss.elastic.co/t/unable-to-find-in-java-client-api-es-8-7-replacement-of-fieldsandweights-in-querystringquerybuilder-of-earlier-version/336285/1 "2023-06-17T19:17:35Z")

</div>

Before ES 8 we were using below query.

```auto
 final BoolQueryBuilder expectedBooleanQuery = QueryBuilders.boolQuery();
    expectedBooleanQuery.must(
        QueryBuilders.queryStringQuery("water")
            .defaultOperator(Operator.AND)
            .fields(
              ImmutableMap.of(
                   "title", 15f,
                   "title-alt", 5f)) 
           .field("some-title", 1f)
            .tieBreaker(1.0f)
            .type(MultiMatchQueryBuilder.Type.MOST_FIELDS));

```

New Java API for 8.x I could not field fields with weight setting in API as MAP

```auto
    final BoolQuery.Builder expectedBooleanQuery = new BoolQuery.Builder().must(
            new Query.Builder().queryString(queryStringQuery -> queryStringQuery.query("water")
                    .defaultOperator(And)
                    .fields(ImmutableList.of("some-title"))
                    .tieBreaker(1.0D)
                    .type(TextQueryType.MostFields)).build().bool()._toQuery());

```

In the new API we can see only .fields(ImmutableList.of("all")) allows List of string but how to set same as earlier version like.  
.fields(  
ImmutableMap.of(  
"title", 15f,  
"title-alt", 5f))

Please advice . much appreciated any help.

---

<div class="post-metadata">

### Author: ![ramyogi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ramyogi/32/120207_2.png) [@ramyogi](https://discuss.elastic.co/u/ramyogi)
#### Post date: [June 18, 2023, 2:22pm UTC](https://discuss.elastic.co/t/unable-to-find-in-java-client-api-es-8-7-replacement-of-fieldsandweights-in-querystringquerybuilder-of-earlier-version/336285/2 "2023-06-18T14:22:02Z")

</div>

Seems no one responding , i noticed similar request.

> [@Elasticsearch 8.5 Java Client increase field weights during search](https://discuss.elastic.co/t/elasticsearch-8-5-java-client-increase-field-weights-during-search/330408):
>
> Hi! I'm trying to figure out how to boost weights for some of the fields in the index during a search. For instance, I have the name field and I'd like Elasticsearch to give it x2 relevance score. Is it possible to do this with the client? When I used version 7 I had a method /\*\* Add several fields to run the query against with a specific boost. \*/ public SimpleQueryStringBuilder fields(Map\<String, Float\> fields) { Objects.requireNonNull(fields, "fields cannot be null"); …

That also no one responded. So can we not able to get any suggestion from any elastic team experts ? No detailed migration guide for every case i agree but any one share the experience helps a lot.

---

<div class="post-metadata">

### Author: ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)
#### Post date: [June 18, 2023, 2:31pm UTC](https://discuss.elastic.co/t/unable-to-find-in-java-client-api-es-8-7-replacement-of-fieldsandweights-in-querystringquerybuilder-of-earlier-version/336285/3 "2023-06-18T14:31:30Z")

</div>

> [@ramyogi](#):
>
> Seems no one responding

It has been less than a day since your initial post and it is a weekend. This forum is manned by volunteers, so it can often take a few days to get an answer. If your question is very specific or around an area limited number of people have experience with it may take longer and it is possible you will not get an answer at all.

If you have not received any response after 2-3 days (excluding weekends) you can up the thread, but remember that there are no SLAs here.

---

<div class="post-metadata">

### Author: ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)
#### Post date: [June 18, 2023, 9:10pm UTC](https://discuss.elastic.co/t/unable-to-find-in-java-client-api-es-8-7-replacement-of-fieldsandweights-in-querystringquerybuilder-of-earlier-version/336285/4 "2023-06-18T21:10:06Z")

</div>

Hi @ramyogi.

Have you tried the same approach where there is field and weight concatenation?

---

<div class="post-metadata">

### Author: ![ramyogi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ramyogi/32/120207_2.png) [@ramyogi](https://discuss.elastic.co/u/ramyogi)
#### Post date: [June 19, 2023, 12:20am UTC](https://discuss.elastic.co/t/unable-to-find-in-java-client-api-es-8-7-replacement-of-fieldsandweights-in-querystringquerybuilder-of-earlier-version/336285/5 "2023-06-19T00:20:16Z")

</div>

If that is the only option through new Java API es client will proceed the implementation but wanted to make sure that. Thanks a lot

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [July 17, 2023, 12:21am UTC](https://discuss.elastic.co/t/unable-to-find-in-java-client-api-es-8-7-replacement-of-fieldsandweights-in-querystringquerybuilder-of-earlier-version/336285/6 "2023-07-17T00:21:08Z")

</div>

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