# Difficulty to perform search operation in an array of items in new Elasticsearchclient library in dotnet

**URL:** <https://discuss.elastic.co/t/difficulty-to-perform-search-operation-in-an-array-of-items-in-new-elasticsearchclient-library-in-dotnet/369513>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [October 28, 2024, 6:59am UTC](https://discuss.elastic.co/t/difficulty-to-perform-search-operation-in-an-array-of-items-in-new-elasticsearchclient-library-in-dotnet/369513 "2024-10-28T06:59:47Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![MARYALA\_VINAY\_KUMAR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/maryala_vinay_kumar/32/138765_2.png) [@MARYALA\_VINAY\_KUMAR](https://discuss.elastic.co/u/MARYALA_VINAY_KUMAR)\
**Post date:** [October 28, 2024, 6:59am UTC](https://discuss.elastic.co/t/difficulty-to-perform-search-operation-in-an-array-of-items-in-new-elasticsearchclient-library-in-dotnet/369513/1 "2024-10-28T06:59:47Z")

</div>

Hi,  
I am trying to run this C# code in dotnet8.0  
using Elastic.Clients.Elasticsearch library version 8.15.10

```auto
var searchResult = await _elasticsearchClient.SearchAsync<Product>(s => s
    .Index("products") // Name of the index
    .Size(0) // Set to 0 if you don't want to return any documents
    .Query(q => q
        .Bool(b => b
            .Must(
                m => m.Terms(t => t
                    .Field(f => f.CategoryId) // Field to match
                    .Terms(categoryIds) // Assume categoryIds is an array of category IDs
                )
            )
        )
    )
);

```

While writing this code, it is showing error (Cannot resolve symbol 'categoryIds') in **.Terms(categoryIds)** line  
Anyone have any idea to resolve this?

---

<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:** [October 28, 2024, 8:28am UTC](https://discuss.elastic.co/t/difficulty-to-perform-search-operation-in-an-array-of-items-in-new-elasticsearchclient-library-in-dotnet/369513/2 "2024-10-28T08:28:11Z")

</div>

Hi,

```auto
cannot resolve symbol 'X'

```

is a compiler error. This means you have not declared the array `categoryIds` (or not declared in the correct scope).

This has nothing to do with the Elasticsearch client itself, but if you show a little bit more code, I'm happy to help you anyways.

---

<div class="post-metadata">

**Author:** ![MARYALA\_VINAY\_KUMAR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/maryala_vinay_kumar/32/138765_2.png) [@MARYALA\_VINAY\_KUMAR](https://discuss.elastic.co/u/MARYALA_VINAY_KUMAR)\
**Post date:** [October 28, 2024, 9:13am UTC](https://discuss.elastic.co/t/difficulty-to-perform-search-operation-in-an-array-of-items-in-new-elasticsearchclient-library-in-dotnet/369513/3 "2024-10-28T09:13:43Z")

</div>

Please find the Code

//code block  
public async Task SearchProductsByCategory()  
{  
// Declare and initialize the array with category IDs to search for  
string categoryIds = { "electronics", "furniture", "clothing" };

```
    // Perform the search
    var searchResult = await _elasticsearchClient.SearchAsync<Product>(s => s
      .Index("products") // Specify the index name
      .Size(0) // Set to 0 if you don't want to return any documents
      .Query(q => q
        .Bool(b => b
          .Must(
            m => m.Terms(t => t
                .Field(f => f.CategoryId) // Field to match in the Product index
                .Terms(categoryIds) // Use the categoryIds array here
            )
          )
        )
      )
    );
    
  }

```

This is the code i am trying in dotnet, The exact problem is,  
there is an error at the part **Must** , **.Terms(categoryIds)** line of the code

These are the problem descriptions found in the riderconsole:

for the line of \*\*.Must( \*\*  
**Ambiguous invocation:  
Elastic.Clients.Elasticsearch.QueryDsl.BoolQueryDescriptor\<Product\> Must(params System.Action\<Elastic.Clients.Elasticsearch.QueryDsl.QueryDescriptor\<Product\>\>[]) (in class BoolQueryDescriptor\<Product\>)  
Elastic.Clients.Elasticsearch.QueryDsl.BoolQueryDescriptor\<Product\> Must(System.Action\<Elastic.Clients.Elasticsearch.QueryDsl.QueryDescriptor\<Product\>\>) (in class BoolQueryDescriptor\<Product\>)  
match**

for the line of .Terms(categoryIds)

**Cannot resolve symbol 'Terms'**

Previously in Nest, i was able to use with no problem at all,  
it wasnt giving this error indication for the same code

---

<div class="post-metadata">

**Author:** ![MARYALA\_VINAY\_KUMAR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/maryala_vinay_kumar/32/138765_2.png) [@MARYALA\_VINAY\_KUMAR](https://discuss.elastic.co/u/MARYALA_VINAY_KUMAR)\
**Post date:** [October 28, 2024, 9:28am UTC](https://discuss.elastic.co/t/difficulty-to-perform-search-operation-in-an-array-of-items-in-new-elasticsearchclient-library-in-dotnet/369513/4 "2024-10-28T09:28:26Z")

</div>

I suspect that by using the new ElasticSearchClient Library, It is not able to identify the second **Terms** statement in the given code

Cannot resolve symbol 'Terms'

---

<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:** [October 28, 2024, 9:38am UTC](https://discuss.elastic.co/t/difficulty-to-perform-search-operation-in-an-array-of-items-in-new-elasticsearchclient-library-in-dotnet/369513/5 "2024-10-28T09:38:03Z")

</div>

Could you please try `Term()` (without the `s`) instead of the second `Terms()`?

---

<div class="post-metadata">

**Author:** ![MARYALA\_VINAY\_KUMAR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/maryala_vinay_kumar/32/138765_2.png) [@MARYALA\_VINAY\_KUMAR](https://discuss.elastic.co/u/MARYALA_VINAY_KUMAR)\
**Post date:** [October 28, 2024, 9:46am UTC](https://discuss.elastic.co/t/difficulty-to-perform-search-operation-in-an-array-of-items-in-new-elasticsearchclient-library-in-dotnet/369513/6 "2024-10-28T09:46:06Z")

</div>

yeah tried,

```
  public async Task SearchProductsByCategory()
  {
    // Declare and initialize the array with category IDs to search for
    string[] categoryIds = { "electronics", "furniture", "clothing" };

    // Perform the search
    var searchResult = await _elasticsearchClient.SearchAsync<Product>(s => s
      .Index("products") // Specify the index name
      .Size(0) // Set to 0 if you don't want to return any documents
      .Query(q => q
        .Bool(
          b => b.Must(m => m.Terms(t => t.Field(f => f.CategoryId).Term(categoryIds)
            )
          )
        )
      )
    );

  }

```

I got this error for this line **b =\> b.Must(m =\> m.Terms(t =\> t.Field(f =\> f.CategoryId).Term(categoryIds)**

Argument type 'string' is not assignable to parameter type 'Elastic.Clients.Elasticsearch.QueryDsl.TermsQueryField'

---

<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:** [October 28, 2024, 10:00am UTC](https://discuss.elastic.co/t/difficulty-to-perform-search-operation-in-an-array-of-items-in-new-elasticsearchclient-library-in-dotnet/369513/7 "2024-10-28T10:00:42Z")

</div>

```csharp
FieldValue[] categoryIds = { "electronics", "furniture", "clothing" };

var searchResult = await client.SearchAsync<Product>(s => s
      .Index("products") // Specify the index name
      .Size(0) // Set to 0 if you don't want to return any documents
      .Query(q => q
        .Bool(b => b
          .Must(
            m => m.Terms(t => t
                .Field(f => f.CategoryId) // Field to match in the Product index
                .Term(new TermsQueryField(categoryIds)) // Use the categoryIds array here
            )
          )
        )
      )
    );

```

---

<div class="post-metadata">

**Author:** ![MARYALA\_VINAY\_KUMAR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/maryala_vinay_kumar/32/138765_2.png) [@MARYALA\_VINAY\_KUMAR](https://discuss.elastic.co/u/MARYALA_VINAY_KUMAR)\
**Post date:** [October 28, 2024, 11:16am UTC](https://discuss.elastic.co/t/difficulty-to-perform-search-operation-in-an-array-of-items-in-new-elasticsearchclient-library-in-dotnet/369513/8 "2024-10-28T11:16:25Z")

</div>

Thanks a lot for this, it has solved my issue
