-
Notifications
You must be signed in to change notification settings - Fork 49
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
TermQuery with empty string value is mistakenly treated as ConditionLess and excluded from search request body #281
Comments
here is another test which I believe is narrowing down the problem
fails with
|
the
|
in fact, a so this may be a serialization configuration issue where objects with value of potentially an issue in the |
this succeeds
but this fails
with
|
think I found it:
I cannot unit test that internal static method but it's clear that a
|
confirmed that's my problem
I would be happy to contribute a fix if someone can
|
it seems that the fix is to update
to:
|
… missing from the request body More properly this test, if accepted as a legit failing expectation should live inside the Tests.Reproduce project but I could not figure out how to run tests in that project. If accepted this can move or be recreated wherever it needs to live
Hi @david-alpert-nl, Thanks for putting in such a concerted effort to investigate the issue and submit a fix, it's greatly appreciated! |
I may have discovered a workaround.
led me to this opensearch-net/src/OpenSearch.Client/QueryDsl/Abstractions/Query/QueryBase.cs Lines 61 to 67 in d2077f4
and now when I add I am going to close this issue as resolved, working as designed, and close GH-283 also. |
Can you think of a place your insight belongs in the docs or user guides?
…On Mon, Jul 17, 2023, 9:43 AM David Alpert (Next League) < ***@***.***> wrote:
Closed #281
<#281> as
completed.
—
Reply to this email directly, view it on GitHub
<#281 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA5PRLTCRA63T2P5HQPOOCTXQVTSZANCNFSM6AAAAAA2LOJEG4>
.
You are receiving this because you are subscribed to this thread.Message
ID: <opensearch-project/opensearch-net/issue/281/issue_event/9840075081@
github.com>
|
…y string serializes as <null>
Further investigation shows that a TermQuery with an empty string value is expected to be 'conditionless' in this codebase and the TermQuery implementation includes a .Verbatim() method to allow the client to serialize the query clause even though it evaluates to conditionless this allows me to create a query like this GET /index/_search { "query": { "bool": { "must": [ {"exists": { "field": "last_name"}} ], "must_not": [ {"term": {"last_name.keyword": {"value": ""}}} ] } } } using the following syntax client.Search<SampleDomainObject>(s => s .Query(q => q .Bool(b => b .Must(m => m.Exists(e => e.Field("last_name"))) .MustNot(m => m.Term(t => t.Verbatim().Field("last_name.keyword").Value(string.Empty))) ) ) .Index("index") .Source(sfd => null) ); thus resolving that opensearch-projectGH-281 is not a bug and is working as designed. Signed-off-by: David Alpert <[email protected]>
great idea; I will look for an opportunity to make that more clear in the docs. |
Thanks @david-alpert-nl. Btw, we've been trying to merge docs closer to the code into https://github.com/opensearch-project/opensearch-net/blob/main/USER_GUIDE.md and will eventually cleanup duplicates. Is this useful here? |
perfect; I can update |
…y string serializes as <null> Signed-off-by: David Alpert <[email protected]>
Further investigation shows that a TermQuery with an empty string value is expected to be 'conditionless' in this codebase and the TermQuery implementation includes a .Verbatim() method to allow the client to serialize the query clause even though it evaluates to conditionless this allows me to create a query like this GET /index/_search { "query": { "bool": { "must": [ {"exists": { "field": "last_name"}} ], "must_not": [ {"term": {"last_name.keyword": {"value": ""}}} ] } } } using the following syntax client.Search<SampleDomainObject>(s => s .Query(q => q .Bool(b => b .Must(m => m.Exists(e => e.Field("last_name"))) .MustNot(m => m.Term(t => t.Verbatim().Field("last_name.keyword").Value(string.Empty))) ) ) .Index("index") .Source(sfd => null) ); thus resolving that opensearch-projectGH-281 is not a bug and is working as designed. Signed-off-by: David Alpert <[email protected]>
…y string serializes as <null> Signed-off-by: David Alpert <[email protected]>
Further investigation shows that a TermQuery with an empty string value is expected to be 'conditionless' in this codebase and the TermQuery implementation includes a .Verbatim() method to allow the client to serialize the query clause even though it evaluates to conditionless this allows me to create a query like this GET /index/_search { "query": { "bool": { "must": [ {"exists": { "field": "last_name"}} ], "must_not": [ {"term": {"last_name.keyword": {"value": ""}}} ] } } } using the following syntax client.Search<SampleDomainObject>(s => s .Query(q => q .Bool(b => b .Must(m => m.Exists(e => e.Field("last_name"))) .MustNot(m => m.Term(t => t.Verbatim().Field("last_name.keyword").Value(string.Empty))) ) ) .Index("index") .Source(sfd => null) ); thus resolving that opensearch-projectGH-281 is not a bug and is working as designed. Signed-off-by: David Alpert <[email protected]>
opensearch-projectGH-281 Signed-off-by: David Alpert <[email protected]>
opensearch-projectGH-281 Signed-off-by: David Alpert <[email protected]>
opensearch-projectGH-281 Signed-off-by: David Alpert <[email protected]>
… ignored as "conditionless" (#283) * test: reproduce GH-281 TermQuery with Value of empty string serializes as <null> Signed-off-by: David Alpert <[email protected]> * test: demonstrate GH-128 is a feature, not a bug Further investigation shows that a TermQuery with an empty string value is expected to be 'conditionless' in this codebase and the TermQuery implementation includes a .Verbatim() method to allow the client to serialize the query clause even though it evaluates to conditionless this allows me to create a query like this GET /index/_search { "query": { "bool": { "must": [ {"exists": { "field": "last_name"}} ], "must_not": [ {"term": {"last_name.keyword": {"value": ""}}} ] } } } using the following syntax client.Search<SampleDomainObject>(s => s .Query(q => q .Bool(b => b .Must(m => m.Exists(e => e.Field("last_name"))) .MustNot(m => m.Term(t => t.Verbatim().Field("last_name.keyword").Value(string.Empty))) ) ) .Index("index") .Source(sfd => null) ); thus resolving that GH-281 is not a bug and is working as designed. Signed-off-by: David Alpert <[email protected]> * refactor: address PR feedback GH-281 Signed-off-by: David Alpert <[email protected]> * docs: update USAGE.md with an example of IsVerbatim/Verbatim() GH-281 Signed-off-by: David Alpert <[email protected]> --------- Signed-off-by: David Alpert <[email protected]>
What is the bug?
When I try to use the
.MustNot(...)
fluent expression to add amust_not
clause to my search query themust_not
part of the expression is missing from the resulting request body.How can one reproduce the bug?
I tried to add a unit test to this project's source code but could not figure out the testing infrastructure in this project.
Instead, consider this scenario (adapted from an existing reproduce test):
What is the expected behavior?
I expect this unit test to pass, successfully converting the
.MustNot(...)
call into amust_not
clause in the search request.Instead it fails returning the following result:
What is your host/environment?
I cloned this repo to my MacOS laptop:
I then locally added a new
Tests.Unit
C# project with the following nuget packages attempting to reproduce the existingTests.Reproduce
dependencies but without the complicated test discovery infrastructure which seems to confuse my JetBrains Rider IDE:xunit/2.5.0
xunit.runner.visualstudio/2.5.0
Microsoft.NET.Test.Sdk/17.6.3
FluentAssertions/6.10.0
Do you have any screenshots?
NOTE: I have updated the code slightly since taking that screenshot to use
e => e.Field("last_name")
instead ofe => e.Field(f => f.LastName))
but the failures still stand.Do you have any additional context?
I created this test case to reproduce an issue where I can submit the following query to an AWS OpenSearch engine using curl or the OpenSearch dashboard:
and the query returns predictably different results whether I include that
must_not
clause.my data set has several documents which have empty
last_name
values and when the query includes themust_not
clause those are filtered out; when the query is missing themust_not
clause like below the documents with emptylast_name
values are includednow I am trying to express that same query with the
must_not
clause using theOpenSearch.SearchAsync<>(...)
method and the fluent query builder and despite trying several different syntax patterns I am unable to generate a request that includes themust_not
clause.The text was updated successfully, but these errors were encountered: