opensearch-project / opensearch-java

Java Client for OpenSearch
Apache License 2.0
124 stars 183 forks source link

[FEATURE] Boost functionality support for MultiMatchQuery #650

Open KaganAddSearch opened 1 year ago

KaganAddSearch commented 1 year ago

We are porting from ES 6.X to OS 2.X. In the old org.elasticsearch.index.query.MultiMatchQueryBuilder there is a field method which accepts field name and the boost value. So each field can be boosted as desired. But with the new org.opensearch.client.opensearch._types.query_dsl.MultiMatchQuery.Builder we don't have a method like this. So we can't set boost values.

I believe having same old field method is required to set the boost values for each field. See below the old method code

    if (Strings.isEmpty(field)) {
      throw new IllegalArgumentException("supplied field is null or empty.");
    } else {
      this.fieldsBoosts.put(field, boost);
      return this;
    }
  }

Although I didn't see any documentation about it but I suspect setting boost values on a field can be achieved via updating the field name. So boost a field named "title" we can add field like this. Even we have this feature should we also have a method for field boost? I think we should. multiMatchQueryBuilder.fields("title^10")

VachaShah commented 1 year ago

@KaganAddSearch Thank you for raising this issue!

As I understand, you are suggesting one of the 2 options:

  1. Add boost field support in MultiMatchQueryBuilder - which is a code change on this repo.
  2. Try to use multiMatchQueryBuilder.fields("title^10") to boost - have you tried this out?
KaganAddSearch commented 1 year ago

@VachaShah We have tried multiMatchQueryBuilder.fields("title^10"). It seems to be working. It is a usable solution but this should be documented. So users don't have to guess this.

VachaShah commented 1 year ago

Thats great @KaganAddSearch! Thank you for getting back on this.

Definitely we should add a test and a working sample in https://github.com/opensearch-project/opensearch-java/tree/main/samples for documentation along with the guides. Would be willing to take this up?

pranishd1 commented 1 year ago

Hi @VachaShah , I would like to work in this issue. Can you please assign it to me?

dblock commented 11 months ago

@pranishd1 Are you still (wanting to) work(ing) on this?

pranishd1 commented 11 months ago

@pranishd1 Are you still (wanting to) work(ing) on this?

@dblock , sorry I am occupied right now.