# ElasticSearch version 8, functionScore with TermsQueryField

**URL:** <https://discuss.elastic.co/t/elasticsearch-version-8-functionscore-with-termsqueryfield/363925>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [July 28, 2024, 2:25pm UTC](https://discuss.elastic.co/t/elasticsearch-version-8-functionscore-with-termsqueryfield/363925 "2024-07-28T14:25:21Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![AMElastic](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/amelastic/32/121862_2.png) [@AMElastic](https://discuss.elastic.co/u/AMElastic)\
**Post date:** [July 28, 2024, 2:25pm UTC](https://discuss.elastic.co/t/elasticsearch-version-8-functionscore-with-termsqueryfield/363925/1 "2024-07-28T14:25:21Z")

</div>

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

```auto
    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.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/6/5/6597ae851d2b4d9e0f4a4f3d2acd61d1ec6b6226.png)

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!

---

<div class="post-metadata">

**Author:** ![Carlos\_D](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carlos_d/32/126245_2.png) [@Carlos\_D](https://discuss.elastic.co/u/Carlos_D)\
**Post date:** [July 29, 2024, 9:59am UTC](https://discuss.elastic.co/t/elasticsearch-version-8-functionscore-with-termsqueryfield/363925/2 "2024-07-29T09:59:47Z")

</div>

From #Elastic Search to #Elasticsearch

---

<div class="post-metadata">

**Author:** ![Carlos\_D](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carlos_d/32/126245_2.png) [@Carlos\_D](https://discuss.elastic.co/u/Carlos_D)\
**Post date:** [July 29, 2024, 9:59am UTC](https://discuss.elastic.co/t/elasticsearch-version-8-functionscore-with-termsqueryfield/363925/3 "2024-07-29T09:59:47Z")

</div>

Added #language-clients

---

<div class="post-metadata">

**Author:** ![flobernd](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flobernd/32/124877_2.png) [@flobernd](https://discuss.elastic.co/u/flobernd)\
**Post date:** [July 29, 2024, 10:46am UTC](https://discuss.elastic.co/t/elasticsearch-version-8-functionscore-with-termsqueryfield/363925/4 "2024-07-29T10:46:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![AMElastic](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/amelastic/32/121862_2.png) [@AMElastic](https://discuss.elastic.co/u/AMElastic)\
**Post date:** [July 29, 2024, 3:28pm UTC](https://discuss.elastic.co/t/elasticsearch-version-8-functionscore-with-termsqueryfield/363925/5 "2024-07-29T15:28:39Z")

</div>

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:

```auto
  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:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/8/a/8a0006e440187f2849530009bd88d55cdcb7706b.png)

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 26, 2024, 3:29pm UTC](https://discuss.elastic.co/t/elasticsearch-version-8-functionscore-with-termsqueryfield/363925/6 "2024-08-26T15:29:14Z")

</div>

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