elastic / elasticsearch-net

This strongly-typed, client library enables working with Elasticsearch. It is the official client maintained and supported by Elastic.
https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/index.html
Apache License 2.0
9 stars 1.15k forks source link

Nested query conditionless check #4021

Closed russcam closed 1 year ago

russcam commented 5 years ago

A nested query has to be marked Verbatim, even when its query is marked Verbatim, because the conditionless check on the nested query does not take into account the query being marked Verbatim.

Consider

var searchResponse = client.Search<Question>(s => s
    .Query(q => q
        .Bool(b1 => b1
            .Must(q1 => q1
                .Nested(n => n
                    .Path("Applicants")
                    .Query(q3 => q3
                        .Term(t => t
                        .Field("Applicants.Surname")
                        .Value("")
                        .Verbatim())
                    )
                ), q1 => q1
                .Term(t => t
                    .Field("Application_Type")
                    .Value("")
                    .Verbatim()
                )
            )
        )
    )
);

The nested query is omitted from the request

{"query":{"bool":{"must":[{"term":{"Application_Type":{"value":""}}}]}}}

because the conditionless check on nested query does not take into account the query being marked Verbatim (or Strict)

https://github.com/elastic/elasticsearch-net/blob/c3301149632df4611bb09da7eb0526db6f3d8ae0/src/Nest/QueryDsl/Joining/Nested/NestedQuery.cs#L39

With the nested query marked as Verbatim(), the query serializes

var searchResponse = client.Search<Question>(s => s
    .Query(q => q
        .Bool(b1 => b1
            .Must(q1 => q1
                .Nested(n => n
                    .Path("Applicants")
                    .Query(q3 => q3
                        .Term(t => t
                        .Field("Applicants.Surname")
                        .Value("")
                        .Verbatim())
                    )
                    .Verbatim()
                ), q1 => q1
                .Term(t => t
                    .Field("Application_Type")
                    .Value("")
                    .Verbatim()
                )
            )
        )
    )
);

yields

{"query":{"bool":{"must":[{"nested":{"path":"Applicants","query":{"term":{"Applicants.Surname":{"value":""}}}}},{"term":{"Application_Type":{"value":""}}}]}}}

Propose that nested query conditionless check should check that query is conditionless only if it is not verbatim or strict.

stevejgordon commented 1 year ago

We've dropped support for conditionless queries in the initial v8 client.