ElasticSearch version 8, functionScore with TermsQueryField

Hi,
I am trying to use FunctionScore in ElasticsearchClient version 8. This is the code that I am using.

    var response = await client.SearchAsync<Model>(s =>
        s.Query(q =>
            q.FunctionScore(fs =>
                fs.Functions(f =>
                    f.RandomScore(r => r.Seed(random.Next(9999)).Field("_seq_no")))
                    .Query(
                    q2=>q2.Bool(b => b
                    .Filter(
                        filter => filter.Terms(t => t.Field(f => f.num).Terms(new TermsQueryField(numbers.Select(number => FieldValue.Long(number)).ToArray())))
                    )
                  )
                )
            )
         )
    .Size(count)
    .Index(indexName)
);

When I run it I get the following error.

In other queries I have used the TermsQueryField. But when I use it in combination with the FunctionScore and Function I am getting this error. How can I solve this?
Thank you!

From Elastic Search to Elasticsearch

Added language-clients

Hi @AMElastic,

this looks like a dependency issue. Please double check if you are using the latest version of Elastic.Clients.Elasticsearch and the latest compatible Elastic.Transport (and make sure to consistently use the same versions in all sub-packages). Sometimes it as well helps to clean the solution and doing a full rebuild.

Hi @flobernd
Thanks for your reply! I had been using Elastic.Client.Elasticsearch version 8.13.12. So I tried to update that to the newest version 8.14.6. But then I am getting an error using term after terms, which till now I didn't have a problem. So the following code I was using up to now:

  filter => filter.Terms(t => t.Field(f => f.num).**Terms**(new TermsQueryField(numbers.Select(number => FieldValue.Long(number)).ToArray())))

which after the upgrade gave me this error:

this forced me to change the second terms to term as follows:
filter => filter.Terms(t => t.Field(f => f.num).**Term**(new TermsQueryField(numbers.Select(number => FieldValue.Long(number)).ToArray())))

I didn't see any documentation regarding this. Is this due to the upgrade? And if so where can I find this documentation, because I didn't see it on the website.
After changing terms to term I did manage to have the funcitonScore together with the TermsQueryField

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