# Elasticsearch 8.5 Java Client increase field weights during search

**URL:** https://discuss.elastic.co/t/elasticsearch-8-5-java-client-increase-field-weights-during-search/330408
**Category:** Elasticsearch
**Tags:** language-clients
**Created:** [April 20, 2023, 4:17pm UTC](https://discuss.elastic.co/t/elasticsearch-8-5-java-client-increase-field-weights-during-search/330408 "2023-04-20T16:17:23Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Denko](https://avatars.discourse-cdn.com/v4/letter/d/779978/32.png) [@Denko](https://discuss.elastic.co/u/Denko)
#### Post date: [April 20, 2023, 4:17pm UTC](https://discuss.elastic.co/t/elasticsearch-8-5-java-client-increase-field-weights-during-search/330408/1 "2023-04-20T16:17:23Z")

</div>

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

```auto
    /** 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");
        for (float fieldBoost : fields.values()) {
            checkNegativeBoost(fieldBoost);
        }
        this.fieldsAndWeights.putAll(fields);
        return this;
    }

```

What is the alternative?

---

<div class="post-metadata">

### Author: ![Denko](https://avatars.discourse-cdn.com/v4/letter/d/779978/32.png) [@Denko](https://discuss.elastic.co/u/Denko)
#### Post date: [April 20, 2023, 4:46pm UTC](https://discuss.elastic.co/t/elasticsearch-8-5-java-client-increase-field-weights-during-search/330408/2 "2023-04-20T16:46:49Z")

</div>

I've found one approach to concatenate ^ sign with a weight to needed fields. For example, `"fields": ["name^2"]` not sure it works though. Will try.

---

<div class="post-metadata">

### Author: ![Denko](https://avatars.discourse-cdn.com/v4/letter/d/779978/32.png) [@Denko](https://discuss.elastic.co/u/Denko)
#### Post date: [April 20, 2023, 5:35pm UTC](https://discuss.elastic.co/t/elasticsearch-8-5-java-client-increase-field-weights-during-search/330408/3 "2023-04-20T17:35:04Z")

</div>

Yes, it works! Though it is not a solution using the client and I'm still wondering if there is one

---

<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: [May 18, 2023, 5:35pm UTC](https://discuss.elastic.co/t/elasticsearch-8-5-java-client-increase-field-weights-during-search/330408/4 "2023-05-18T17:35:26Z")

</div>

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