elastic / elasticsearch-java

Official Elasticsearch Java Client
Apache License 2.0
410 stars 239 forks source link

use gauss function, but request with linear function #279

Open Honeylemonade opened 2 years ago

Honeylemonade commented 2 years ago

Java API client version

8.2.0

Java version

8

Elasticsearch Version

7.17.3

Problem description

image

I use [logging: level: tracer : TRACE] springboot conf to see the ES request, found that when I send a request with functionScore of gauss, but the request log shows it sended the functionScore of linear as the front pic

ayhankaraa commented 8 months ago

It has been a while since this question asked, however if anyone ends up here because of the same problem, as I did, you can try to use the alternative method:

public static FunctionScore gauss(Function<DecayFunction.Builder, ObjectBuilder<DecayFunction>> fn)

this correctly sets the kind:

this._kind = Kind.Gauss;
l-trotta commented 7 months ago

Thanks for the report, this is probably an issue with the java client code generator, it affects both the gauss and exp variants of the functions by setting them as linear if that specific builder is used. As @ayhankaraa kindly reported, using the alternative version of the builder works because this one isn't affected, for example:

        FunctionScore fs = FunctionScoreBuilders.gauss(g -> g
                .field("location")
                .placement(p -> p
                    .origin(JsonData.of("something"))));

Once the generator is fixed, the Java client code will be updated to resolve this issue.