Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating nested function score query from json via supplied reader #917

Open
Jangis93 opened this issue Dec 12, 2024 · 1 comment
Open
Labels
Area: Helpers Category: Bug Something isn't working

Comments

@Jangis93
Copy link

Jangis93 commented Dec 12, 2024

Java API client version

8.16.1

Java version

OpenJDK Runtime Environment Temurin-21.0.2+13

Elasticsearch Version

8.14.3

Problem description

Hello,

It seems like the fromJson method on the FuncitonScoreQuery object works differently with the latest client.

In our test setup we are using a function like this to create a query fixture from a supplied json which worked fine before the upgrade of the Java client, from 8.14.1 -> 8.16.1.

public static FunctionScoreQuery functionScoreQueryFromFile(String fileContent) {
		return FunctionScoreQuery.of(q1 -> q1.withJson(new StringReader(fileContent))));
}

The use case that we are having problems with is when we have a nested function score query like this:

{
  "functions": [
    {
      "field_value_factor": {
       ... 
      }
    }
  ],
  "query": {
    "function_score": {
      "query": {
        ...
      }
    }
  }
}

And we get the following error:

co.elastic.clients.json.JsonpMappingException: Error deserializing co.elastic.clients.elasticsearch._types.query_dsl.FunctionScore: Unknown field 'query' (JSON path: query.function_score.query)

Is this use case not valid anymore?

@l-trotta
Copy link
Contributor

Hello, thanks for reporting this!

This is probably a side effect of this PR that we didn't notice at the time. We wanted to add support for the deserialization of the shortcut version of FunctionScoreQuery, and it seems like we accidentally broke it for this case.

I suggest using the java DSL to perform the call while we work on solving the issue, let me know if you need any help with translating - and sorry for the inconvenience!

@l-trotta l-trotta added Category: Bug Something isn't working Area: Helpers labels Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Helpers Category: Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants