opensearch-project / opensearch-project/opensearch-java

Unable to create gauss decay function in java client

Open
#811 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Java
Stars
165
Forks
250
Avg merge
1d 18h
Merged PRs (30d)
26

Description

What is the bug?

Unable to create a function score query using decay functions(gauss, linear, exp)

How can one reproduce the bug?

One should have a field in opensearch with java mapping as double ( field : rating)
Create a function score query and add a gauss function or any decay function and run a query. One should get 400 bad request error in all possible combinations.

What is the expected behavior?

A query should produce a result having _score of documents adjusted as per the decay function.

What is your host/environment?

AWS ECS Fargate

Do you have any screenshots?
Do you have any additional context?

query snippet

{
          "filter": {
            "bool": {
              "must": {
                "query_string": {
                  "fields": [
                    "name"
                  ],
                  "query": "akshay"
                }
              }
            }
          },
          "gauss": {
            "rating": {
              "decay": 0.85,
              "offset": "0",
              "origin": "10",
              "scale": "0.5"
            }
          },
          "weight": 999
        }

Java Code

 var ratingScore = new FunctionScore.Builder().gauss(decay -> decay.field("rating").placement(
                        dp -> dp.origin(JsonData.of("10")).scale(JsonData.of("5")))
                .weight(999d).filter(QueryUtils.getQueryStringQuery("akshay", "name")._toQuery())).build();

        fsq.functions(List.of(popularityScore, ratingScore))
            .query(boolQueryBuilder.build()._toQuery())
            .scoreMode(FunctionScoreMode.Max)
            .boostMode(FunctionBoostMode.Replace);

fsq -> instance of function score query builder

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Java FunctionScore builder snippet and the JSON query shown in the issue, then reproduce a function score query using the gauss decay function on a double rating field. Compare the serialized request with the query accepted by OpenSearch and capture the 400 response. Done means gauss, linear, and exp decay functions can run and adjust document scores without a bad request.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.