Skip to content

A part of query is dropped from client.Search #6033

@sherry-ger

Description

@sherry-ger

NEST/Elasticsearch.Net version:
version 7.15

Elasticsearch version:
7.15

.NET runtime version:

Operating system version:

Description of the problem including expected versus actual behavior:
The second clause of a query is dropped.

Steps to reproduce:

code snippet:

            var translateRequest = new TranslateSqlRequest();
            translateRequest.Query = “select * from A where X = 1 and Y like ‘%B%’”;
            var translateResponse = client.Sql.Translate(translateRequest);
            var elasticQuery = translateResponse.Result;
            var result = client.Search<K>(elasticQuery);

So basically translate sql query ( highlevel client ) and then take translated query from response and try to actually run the search. (I know there is a workaround but that is a different issue unfortunately.)

Now what happens is that translation goes well and I can see proper translated query ( below )

Result:

"query" : {
    "bool" : {
      "must" : [
        {     "term" : { "X" : { "value" : "1", "boost" : 1.0            }         }      },
        {     "wildcard" : {  "B.keyword" : {  "wildcard" : "*B*",  "boost" : 1.0   }     }     }
      ],
      "adjust_pure_negative" : true,
      "boost" : 1.0
    }
  },

But for some reason why I pass it to search the second condition is vanishing from query.

It returns results like the query was “select * from A where X = 1” which it is not.

I enabled debug mode and I can see that indeed executed query is:

{"from":0,"query":{"bool":{"must":[{"term":{"A":{"value":1,"boost":1.0}}}],"boost":1.0}},"size":100,"sort":[{"B.keyword":{"unmapped_type":"keyword","missing":"_last","order":"asc"}}],"_source":true}

AS you can see whole { "wildcard" : { "B.keyword" : { "wildcard" : "*B*", "boost" : 1.0 } } } is missing from it.

It appears range query as second condition does not work as well.

Expected behavior
A clear and concise description of what you expected to happen.

Provide ConnectionSettings (if relevant):

Provide DebugInformation (if relevant):

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions