Skip to content

QueryStringQuery fails when a single field is set for the Fields array #8046

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

Closed
baveryt opened this issue Feb 23, 2024 · 1 comment
Closed
Labels
8.x Relates to a 8.x client version Duplicate

Comments

@baveryt
Copy link

baveryt commented Feb 23, 2024

Elastic.Clients.Elasticsearch version: 8.12.0

Elasticsearch version: 8.8.1

.NET runtime version: 8.0.2

Operating system version: OSX

Description of the problem including expected versus actual behavior:
When attempting to build a QueryString that contains just 1 field in the Fields array list the deserialization generates an invalid search body into elastic. This is a new problem with the 8.12 release and was working as expected in the 8.11 release.

Code like:

new QueryStringQuery()
{
   Query = "test",
   Fields = new List<string> {"field1"}.ToArray()
}

The body going into elastic will look like:

{
    "query_string": {
      "fields": "field1",
      "query": "test"
    }

Notice that the fields member is a string value rather than an array. This fails on the elastic search cluster. When building with multiple field values the string is generated properly:

new QueryStringQuery()
{
   Query = "test",
   Fields = new List<string> {"field1", "field2"}.ToArray()
}

The body going into elastic will look like:

{
    "query_string": {
      "fields": ["field1", "field2"],
      "query": "test"
    }

And this generates valid code for the elastic cluster.

Expected behavior
Build out the fields as an array regardless of how many items are in the fields array as it was doing in the 8.11 release.

@baveryt baveryt added the 8.x Relates to a 8.x client version label Feb 23, 2024
@baveryt
Copy link
Author

baveryt commented Feb 26, 2024

Sorry I see this is a duplicate of #8036

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
8.x Relates to a 8.x client version Duplicate
Projects
None yet
Development

No branches or pull requests

2 participants