Skip to content

Query on multiple fields using "fluent" syntax generates broken DSL. #8717

@sictransit

Description

@sictransit

Elastic.Clients.Elasticsearch version: 8.19.7

Elasticsearch version: 8.16.1

.NET runtime version: 8.0.20

Operating system version: Windows 11 Enterprise 23H2

Description of the problem including expected versus actual behavior:

In NEST it was possible to create fluent queries on multiple fields like this:
.Fields(f => f.Field(ff => ff.Name).Field(ff => ff.Path))

That syntax is no longer available. When I try to do something similar I get an unexpected behaviour.

var query = new QueryDescriptor<Document>().QueryString(qs => qs
    .Fields(f => new[] { f.Name, f.Path })
    .Query("title"));

var request = new SearchRequestDescriptor<Document>().Query(query);
request.Indices(PrependPrefix(typeof(Document).ElasticsearchIndexName()));
var response = Client.Search<Document>(request);

Generated DSL:

{
  "query": {
    "query_string": {
      "fields": [
        "path.name"
      ],
      "query": "title"
    }
  }
}

Expected behavior

I'm expecting the fields to be an array instead of concatenated to a single string with a dot separator.

{
  "query": {
    "query_string": {
      "fields": [
        "name",
        "path"
      ],
      "query": "title"
    }
  }
}

Workarounds

This generates a proper query:

var query = new QueryDescriptor<Document>().QueryString(qs => qs
	.Fields("name, path")
	.Query("title"));

This more fluent syntax also seems to work:

var fields = Fields.FromFields(
[
    Infer.Field<Document>(i => i.Name),
    Infer.Field<Document>(i => i.Path)
]);

var query = new QueryDescriptor<Document>().QueryString(qs => qs
    .Fields(fields)
    .Query("title"));

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions