Skip to content
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

GH-281 TermQuery with a string.Empty value needs .Verbatim() or it is ignored as "conditionless" #283

Conversation

davidalpert
Copy link
Contributor

@davidalpert davidalpert commented Jul 16, 2023

Description

Issues Resolved

Resolves GH-281

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Signed-off-by: David Alpert [email protected]

Copy link
Collaborator

@Xtansia Xtansia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix looks good, only thing missing is we'll need an entry added into the CHANGELOG.md under a ### Fixed header in the ## Unreleased section.

I think there might also be value in adding a reproduce test similar to the one you shared here: #281 (comment)

@Xtansia
Copy link
Collaborator

Xtansia commented Jul 16, 2023

@davidalpert It does appear unfortunately this fix breaks some test cases that expect empty string to be conditionless.

I'm aware of your issue #282, there's unfortunately some flaky tests in general that make running the tests locally frustrating. The reproduce command from below (./build.sh seed:6572 random:sourceserializer:false random:typedkeys:false random:httpcompression test "andoperator,notoperator,oroperator,unaryaddoperator,booldslcomplexquery,prefixquery,termquery,termquerywithcaseinsensitive,wildcardquery,strictquery") should help so that you don't need to deal with any flaky tests and only worry about those affected by this change.

2023-07-16T22:32:13.5940655Z Test run for /home/runner/work/opensearch-net/opensearch-net/tests/Tests/bin/Release/net6.0/Tests.dll (.NETCoreApp,Version=v6.0)
2023-07-16T22:32:13.8014200Z Starting test execution, please wait...
2023-07-16T22:32:13.8489056Z A total of 1 test files matched the specified pattern.
2023-07-16T22:32:17.1270423Z --------------------
2023-07-16T22:32:17.1271400Z Starting tests using config:
2023-07-16T22:32:17.1272373Z  - TestAgainstAlreadyRunningOpenSearch: False
2023-07-16T22:32:17.1273192Z  - OpenSearchVersion: 1.0.0
2023-07-16T22:32:17.1273758Z  - Mode: Unit
2023-07-16T22:32:17.1275113Z  - Seed: 6572
2023-07-16T22:32:17.1275750Z  - ForceReseed: False
2023-07-16T22:32:17.1277490Z  - TestOnlyOne: False
2023-07-16T22:32:17.1322191Z  - RunIntegrationTests: False
2023-07-16T22:32:17.1322676Z  - RunUnitTests: True
2023-07-16T22:32:17.1322990Z  - Random:
2023-07-16T22:32:17.1323259Z  	- SourceSerializer: False
2023-07-16T22:32:17.1323595Z  	- TypedKeys: False
2023-07-16T22:32:17.1323932Z  	- HttpCompression: True
2023-07-16T22:32:17.1324322Z --------------------
2023-07-16T22:32:19.3101117Z [xUnit.net 00:00:04.81]     Tests.QueryDsl.TermLevel.Wildcard.WildcardQueryUsageTests.ConditionlessWhenExpectedToBe [FAIL]
2023-07-16T22:32:19.3323152Z   Failed Tests.QueryDsl.TermLevel.Wildcard.WildcardQueryUsageTests.ConditionlessWhenExpectedToBe [7 ms]
2023-07-16T22:32:19.3325000Z   Error Message:
2023-07-16T22:32:19.3326103Z    Expected q.Conditionless to be true, but found False.
2023-07-16T22:32:19.3326440Z   Stack Trace:
2023-07-16T22:32:19.3326897Z      at FluentAssertions.Execution.XUnit2TestFramework.Throw(String message)
2023-07-16T22:32:19.3327486Z    at FluentAssertions.Execution.TestFrameworkProvider.Throw(String message)
2023-07-16T22:32:19.3328140Z    at FluentAssertions.Execution.DefaultAssertionStrategy.HandleFailure(String message)
2023-07-16T22:32:19.3328753Z    at FluentAssertions.Execution.AssertionScope.FailWith(Func`1 failReasonFunc)
2023-07-16T22:32:19.3329316Z    at FluentAssertions.Execution.AssertionScope.FailWith(Func`1 failReasonFunc)
2023-07-16T22:32:19.3329949Z    at FluentAssertions.Execution.AssertionScope.FailWith(String message, Object[] args)
2023-07-16T22:32:19.3330550Z    at FluentAssertions.Primitives.BooleanAssertions`1.BeTrue(String because, Object[] becauseArgs)
2023-07-16T22:32:19.3331682Z    at Tests.QueryDsl.ConditionlessWhen`1.Assert(IQueryContainer c, Action`1 when) in /home/runner/work/opensearch-net/opensearch-net/tests/Tests/QueryDsl/ConditionlessWhen.cs:line 52
2023-07-16T22:32:19.3332932Z    at Tests.QueryDsl.ConditionlessWhen`1.<>c__DisplayClass2_0.<Add>b__0(QueryContainer q) in /home/runner/work/opensearch-net/opensearch-net/tests/Tests/QueryDsl/ConditionlessWhen.cs:line 44
2023-07-16T22:32:19.3334089Z    at Tests.QueryDsl.QueryDslUsageTestsBase.ConditionlessWhenExpectedToBe() in /home/runner/work/opensearch-net/opensearch-net/tests/Tests/QueryDsl/QueryDslUsageTestsBase.cs:line 117
2023-07-16T22:32:19.9839223Z [xUnit.net 00:00:05.48]     Tests.QueryDsl.TermLevel.Term.TermQueryWithCaseInsensitiveUsageTests.ConditionlessWhenExpectedToBe [FAIL]
2023-07-16T22:32:19.9968133Z   Failed Tests.QueryDsl.TermLevel.Term.TermQueryWithCaseInsensitiveUsageTests.ConditionlessWhenExpectedToBe [2 ms]
2023-07-16T22:32:20.0011016Z   Error Message:
2023-07-16T22:32:20.0011810Z    Expected q.Conditionless to be true, but found False.
2023-07-16T22:32:20.0012494Z   Stack Trace:
2023-07-16T22:32:20.0013277Z      at FluentAssertions.Execution.XUnit2TestFramework.Throw(String message)
2023-07-16T22:32:20.0014199Z    at FluentAssertions.Execution.TestFrameworkProvider.Throw(String message)
2023-07-16T22:32:20.0015324Z    at FluentAssertions.Execution.DefaultAssertionStrategy.HandleFailure(String message)
2023-07-16T22:32:20.0016205Z    at FluentAssertions.Execution.AssertionScope.FailWith(Func`1 failReasonFunc)
2023-07-16T22:32:20.0110015Z    at FluentAssertions.Execution.AssertionScope.FailWith(Func`1 failReasonFunc)
2023-07-16T22:32:20.0110879Z    at FluentAssertions.Execution.AssertionScope.FailWith(String message, Object[] args)
2023-07-16T22:32:20.0111538Z    at FluentAssertions.Primitives.BooleanAssertions`1.BeTrue(String because, Object[] becauseArgs)
2023-07-16T22:32:20.0113055Z    at Tests.QueryDsl.ConditionlessWhen`1.Assert(IQueryContainer c, Action`1 when) in /home/runner/work/opensearch-net/opensearch-net/tests/Tests/QueryDsl/ConditionlessWhen.cs:line 52
2023-07-16T22:32:20.0114319Z    at Tests.QueryDsl.ConditionlessWhen`1.<>c__DisplayClass2_0.<Add>b__0(QueryContainer q) in /home/runner/work/opensearch-net/opensearch-net/tests/Tests/QueryDsl/ConditionlessWhen.cs:line 44
2023-07-16T22:32:20.0115350Z    at Tests.QueryDsl.QueryDslUsageTestsBase.ConditionlessWhenExpectedToBe() in /home/runner/work/opensearch-net/opensearch-net/tests/Tests/QueryDsl/QueryDslUsageTestsBase.cs:line 117
2023-07-16T22:32:20.6969917Z [xUnit.net 00:00:06.19]     Tests.QueryDsl.TermLevel.Term.TermQueryUsageTests.ConditionlessWhenExpectedToBe [FAIL]
2023-07-16T22:32:20.7214077Z   Failed Tests.QueryDsl.TermLevel.Term.TermQueryUsageTests.ConditionlessWhenExpectedToBe [1 ms]
2023-07-16T22:32:20.7240312Z   Error Message:
2023-07-16T22:32:20.7241036Z    Expected q.Conditionless to be true, but found False.
2023-07-16T22:32:20.7243051Z   Stack Trace:
2023-07-16T22:32:20.7243913Z      at FluentAssertions.Execution.XUnit2TestFramework.Throw(String message)
2023-07-16T22:32:20.7245294Z    at FluentAssertions.Execution.TestFrameworkProvider.Throw(String message)
2023-07-16T22:32:20.7246296Z    at FluentAssertions.Execution.DefaultAssertionStrategy.HandleFailure(String message)
2023-07-16T22:32:20.7247123Z    at FluentAssertions.Execution.AssertionScope.FailWith(Func`1 failReasonFunc)
2023-07-16T22:32:20.7248104Z    at FluentAssertions.Execution.AssertionScope.FailWith(Func`1 failReasonFunc)
2023-07-16T22:32:20.7248871Z    at FluentAssertions.Execution.AssertionScope.FailWith(String message, Object[] args)
2023-07-16T22:32:20.7249642Z    at FluentAssertions.Primitives.BooleanAssertions`1.BeTrue(String because, Object[] becauseArgs)
2023-07-16T22:32:20.7250953Z    at Tests.QueryDsl.ConditionlessWhen`1.Assert(IQueryContainer c, Action`1 when) in /home/runner/work/opensearch-net/opensearch-net/tests/Tests/QueryDsl/ConditionlessWhen.cs:line 52
2023-07-16T22:32:20.7252513Z    at Tests.QueryDsl.ConditionlessWhen`1.<>c__DisplayClass2_0.<Add>b__0(QueryContainer q) in /home/runner/work/opensearch-net/opensearch-net/tests/Tests/QueryDsl/ConditionlessWhen.cs:line 44
2023-07-16T22:32:20.7254308Z    at Tests.QueryDsl.QueryDslUsageTestsBase.ConditionlessWhenExpectedToBe() in /home/runner/work/opensearch-net/opensearch-net/tests/Tests/QueryDsl/QueryDslUsageTestsBase.cs:line 117
2023-07-16T22:32:22.6666022Z [xUnit.net 00:00:08.15]     Tests.QueryDsl.Compound.Bool.BoolDslComplexQueryUsageTests.SerializesFluent [FAIL]
2023-07-16T22:32:22.6872532Z   Failed Tests.QueryDsl.Compound.Bool.BoolDslComplexQueryUsageTests.SerializesFluent [79 ms]
2023-07-16T22:32:22.6883976Z   Error Message:
2023-07-16T22:32:22.6884781Z    System.Exception : Expected serialization to succeed but failed.
2023-07-16T22:32:22.6885761Z RoundTrip: 0 iteration
2023-07-16T22:32:22.6886189Z Deserialization has result: False
2023-07-16T22:32:22.6886545Z RoundTripResult`1 success: False
2023-07-16T22:32:22.6887020Z This is the first time I am serializing
2023-07-16T22:32:22.6887361Z   {
2023-07-16T22:32:22.6887685Z     "query": {
2023-07-16T22:32:22.6888074Z       "bool": {
2023-07-16T22:32:22.6888353Z         "should": [
2023-07-16T22:32:22.6888655Z           {
2023-07-16T22:32:22.6888954Z             "bool": {
2023-07-16T22:32:22.6889266Z               "must": [
2023-07-16T22:32:22.6889652Z                 {
2023-07-16T22:32:22.6890051Z                   "term": {
2023-07-16T22:32:22.6890366Z                     "x": {
2023-07-16T22:32:22.6890716Z                       "value": "y"
2023-07-16T22:32:22.6891039Z                     }
2023-07-16T22:32:22.6891514Z                   }
2023-07-16T22:32:22.6891803Z                 },
2023-07-16T22:32:22.6892088Z                 {
2023-07-16T22:32:22.6892432Z                   "term": {
2023-07-16T22:32:22.6892688Z                     "x": {
2023-07-16T22:32:22.6893001Z                       "value": "y"
2023-07-16T22:32:22.6893306Z                     }
2023-07-16T22:32:22.6893604Z                   }
2023-07-16T22:32:22.6893932Z                 }
2023-07-16T22:32:22.6894181Z               ]
2023-07-16T22:32:22.6894461Z             }
2023-07-16T22:32:22.6894740Z           },
2023-07-16T22:32:22.6895075Z           {
2023-07-16T22:32:22.6895380Z             "bool": {
2023-07-16T22:32:22.6895714Z               "must": [
2023-07-16T22:32:22.6896035Z                 {
2023-07-16T22:32:22.6896344Z                   "bool": {
2023-07-16T22:32:22.6896978Z                     "should": [
2023-07-16T22:32:22.6897288Z                       {
2023-07-16T22:32:22.6897538Z                         "bool": {
2023-07-16T22:32:22.6897865Z                           "filter": [
2023-07-16T22:32:22.6898226Z                             {
2023-07-16T22:32:22.6898543Z                               "term": {
2023-07-16T22:32:22.6898862Z                                 "x": {
2023-07-16T22:32:22.6899151Z                                   "value": "y"
2023-07-16T22:32:22.6899471Z                                 }
2023-07-16T22:32:22.6899819Z                               }
2023-07-16T22:32:22.6900562Z                             }
2023-07-16T22:32:22.6900880Z                           ]
2023-07-16T22:32:22.6901129Z                         }
2023-07-16T22:32:22.6901473Z                       },
2023-07-16T22:32:22.6901779Z                       {
2023-07-16T22:32:22.6902122Z                         "bool": {
2023-07-16T22:32:22.6902443Z                           "filter": [
2023-07-16T22:32:22.6902703Z                             {
2023-07-16T22:32:22.6903061Z                               "term": {
2023-07-16T22:32:22.6903394Z                                 "x": {
2023-07-16T22:32:22.6903725Z                                   "value": "y"
2023-07-16T22:32:22.6904042Z                                 }
2023-07-16T22:32:22.6904509Z                               }
2023-07-16T22:32:22.6904775Z                             }
2023-07-16T22:32:22.6905075Z                           ]
2023-07-16T22:32:22.6905372Z                         }
2023-07-16T22:32:22.6905706Z                       },
2023-07-16T22:32:22.7181637Z                       {
2023-07-16T22:32:22.7182049Z                         "bool": {
2023-07-16T22:32:22.7182318Z                           "must_not": [
2023-07-16T22:32:22.7182570Z                             {
2023-07-16T22:32:22.7183255Z                               "term": {
2023-07-16T22:32:22.7183521Z                                 "x": {
2023-07-16T22:32:22.7183788Z                                   "value": "y"
2023-07-16T22:32:22.7184042Z                                 }
2023-07-16T22:32:22.7184278Z                               }
2023-07-16T22:32:22.7184502Z                             },
2023-07-16T22:32:22.7184720Z                             {
2023-07-16T22:32:22.7184958Z                               "term": {
2023-07-16T22:32:22.7185207Z                                 "x": {
2023-07-16T22:32:22.7185466Z                                   "value": "y"
2023-07-16T22:32:22.7185718Z                                 }
2023-07-16T22:32:22.7185937Z                               }
2023-07-16T22:32:22.7186228Z +                           },
2023-07-16T22:32:22.7186487Z +                           {
2023-07-16T22:32:22.7186760Z +                             "term": {
2023-07-16T22:32:22.7187029Z +                               "x": {
2023-07-16T22:32:22.7187317Z +                                 "value": ""
2023-07-16T22:32:22.7187552Z                                 }
2023-07-16T22:32:22.7187810Z +                             }
2023-07-16T22:32:22.7188061Z +                           }
2023-07-16T22:32:22.7188295Z                           ]
2023-07-16T22:32:22.7188517Z                         }
2023-07-16T22:32:22.7188726Z                       }
2023-07-16T22:32:22.7188949Z                     ]
2023-07-16T22:32:22.7189169Z                   }
2023-07-16T22:32:22.7189388Z                 },
2023-07-16T22:32:22.7189766Z                 {
2023-07-16T22:32:22.7189967Z                   "bool": {
2023-07-16T22:32:22.7190200Z                     "should": [
2023-07-16T22:32:22.7190436Z                       {
2023-07-16T22:32:22.7190661Z                         "term": {
2023-07-16T22:32:22.7190893Z                           "x": {
2023-07-16T22:32:22.7191114Z                             "value": "y"
2023-07-16T22:32:22.7191357Z                           }
2023-07-16T22:32:22.7191580Z                         }
2023-07-16T22:32:22.7191799Z                       },
2023-07-16T22:32:22.7192015Z                       {
2023-07-16T22:32:22.7192221Z                         "term": {
2023-07-16T22:32:22.7192453Z                           "x": {
2023-07-16T22:32:22.7192694Z                             "value": "y"
2023-07-16T22:32:22.7192927Z                           }
2023-07-16T22:32:22.7193144Z                         }
2023-07-16T22:32:22.7193344Z                       },
2023-07-16T22:32:22.7193558Z                       {
2023-07-16T22:32:22.7193782Z                         "term": {
2023-07-16T22:32:22.7194011Z                           "x": {
2023-07-16T22:32:22.7194248Z                             "value": "y"
2023-07-16T22:32:22.7194703Z +                         }
2023-07-16T22:32:22.7194939Z +                       }
2023-07-16T22:32:22.7195177Z +                     }
2023-07-16T22:32:22.7195413Z +                   ]
2023-07-16T22:32:22.7195651Z +                 }
2023-07-16T22:32:22.7195861Z +               },
2023-07-16T22:32:22.7196072Z +               {
2023-07-16T22:32:22.7196305Z +                 "bool": {
2023-07-16T22:32:22.7196556Z +                   "should": [
2023-07-16T22:32:22.7196798Z +                     {
2023-07-16T22:32:22.7197027Z +                       "term": {
2023-07-16T22:32:22.7197279Z +                         "x": {
2023-07-16T22:32:22.7197820Z +                           "value": ""
2023-07-16T22:32:22.7198092Z +                         }
2023-07-16T22:32:22.7198346Z +                       }
2023-07-16T22:32:22.7198768Z +                     },
2023-07-16T22:32:22.7199003Z +                     {
2023-07-16T22:32:22.7199262Z +                       "bool": {
2023-07-16T22:32:22.7199548Z +                         "filter": [
2023-07-16T22:32:22.7199821Z +                           {
2023-07-16T22:32:22.7200095Z +                             "term": {
2023-07-16T22:32:22.7200362Z +                               "x": {
2023-07-16T22:32:22.7200964Z +                                 "value": ""
2023-07-16T22:32:22.7201264Z +                               }
2023-07-16T22:32:22.7201527Z +                             }
2023-07-16T22:32:22.7201936Z +                           }
2023-07-16T22:32:22.7202164Z +                         ]
2023-07-16T22:32:22.7202407Z +                       }
2023-07-16T22:32:22.7202644Z +                     },
2023-07-16T22:32:22.7202883Z +                     {
2023-07-16T22:32:22.7203129Z +                       "bool": {
2023-07-16T22:32:22.7203379Z +                         "must_not": [
2023-07-16T22:32:22.7203632Z +                           {
2023-07-16T22:32:22.7203889Z +                             "term": {
2023-07-16T22:32:22.7204160Z +                               "x": {
2023-07-16T22:32:22.7204437Z +                                 "value": ""
2023-07-16T22:32:22.7204698Z +                               }
2023-07-16T22:32:22.7204931Z +                             }
2023-07-16T22:32:22.7205164Z                             }
2023-07-16T22:32:22.7205406Z +                         ]
2023-07-16T22:32:22.7205629Z                         }
2023-07-16T22:32:22.7205851Z                       }
2023-07-16T22:32:22.7206052Z                     ]
2023-07-16T22:32:22.7206267Z                   }
2023-07-16T22:32:22.7206478Z                 },
2023-07-16T22:32:22.7206689Z                 {
2023-07-16T22:32:22.7206907Z                   "bool": {
2023-07-16T22:32:22.7207127Z                     "boost": 2.0,
2023-07-16T22:32:22.7207368Z                     "filter": [
2023-07-16T22:32:22.7207593Z                       {
2023-07-16T22:32:22.7207827Z                         "match_all": {}
2023-07-16T22:32:22.7208061Z                       }
2023-07-16T22:32:22.7208270Z                     ],
2023-07-16T22:32:22.7208523Z                     "minimum_should_match": 1,
2023-07-16T22:32:22.7208766Z                     "must": [
2023-07-16T22:32:22.7208983Z                       {
2023-07-16T22:32:22.7209223Z                         "match_all": {}
2023-07-16T22:32:22.7209434Z                       }
2023-07-16T22:32:22.7209640Z                   
2023-07-16T22:32:22.7209768Z 
2023-07-16T22:32:22.7209854Z   Stack Trace:
2023-07-16T22:32:22.7211049Z      at Tests.Core.Extensions.SerializationTesterAssertionExtensions.ShouldBeValid(SerializationResult result, String message) in /home/runner/work/opensearch-net/opensearch-net/tests/Tests.Core/Extensions/SerializationTesterAssertionExtensions.cs:line 40
2023-07-16T22:32:22.7212774Z    at Tests.Core.Extensions.SerializationTesterAssertionExtensions.AssertRoundTrip[T](SerializationTester tester, T object, Object expectedJson, String message, Boolean preserveNullInExpected) in /home/runner/work/opensearch-net/opensearch-net/tests/Tests.Core/Extensions/SerializationTesterAssertionExtensions.cs:line 57
2023-07-16T22:32:22.7214301Z    at Tests.Core.Serialization.ExpectJsonTestBase.RoundTripsOrSerializes[T](T object) in /home/runner/work/opensearch-net/opensearch-net/tests/Tests.Core/Serialization/ExpectJsonTestBase.cs:line 50
2023-07-16T22:32:22.7215739Z    at Tests.Framework.EndpointTests.ApiTestBase`5.SerializesFluent() in /home/runner/work/opensearch-net/opensearch-net/tests/Tests/Framework/EndpointTests/ApiTestBase.cs:line 63
2023-07-16T22:32:23.3501706Z [xUnit.net 00:00:08.85]     Tests.QueryDsl.TermLevel.Prefix.PrefixQueryUsageTests.ConditionlessWhenExpectedToBe [FAIL]
2023-07-16T22:32:23.3835687Z   Failed Tests.QueryDsl.TermLevel.Prefix.PrefixQueryUsageTests.ConditionlessWhenExpectedToBe [9 ms]
2023-07-16T22:32:23.3836424Z   Error Message:
2023-07-16T22:32:23.3836805Z    Expected q.Conditionless to be true, but found False.
2023-07-16T22:32:23.3837153Z   Stack Trace:
2023-07-16T22:32:23.3838517Z      at FluentAssertions.Execution.XUnit2TestFramework.Throw(String message)
2023-07-16T22:32:23.3839369Z    at FluentAssertions.Execution.TestFrameworkProvider.Throw(String message)
2023-07-16T22:32:23.3840669Z    at FluentAssertions.Execution.DefaultAssertionStrategy.HandleFailure(String message)
2023-07-16T22:32:23.3841602Z    at FluentAssertions.Execution.AssertionScope.FailWith(Func`1 failReasonFunc)
2023-07-16T22:32:23.3842454Z    at FluentAssertions.Execution.AssertionScope.FailWith(Func`1 failReasonFunc)
2023-07-16T22:32:23.3843070Z    at FluentAssertions.Execution.AssertionScope.FailWith(String message, Object[] args)
2023-07-16T22:32:23.3843714Z    at FluentAssertions.Primitives.BooleanAssertions`1.BeTrue(String because, Object[] becauseArgs)
2023-07-16T22:32:23.3845207Z    at Tests.QueryDsl.ConditionlessWhen`1.Assert(IQueryContainer c, Action`1 when) in /home/runner/work/opensearch-net/opensearch-net/tests/Tests/QueryDsl/ConditionlessWhen.cs:line 52
2023-07-16T22:32:23.3846198Z    at Tests.QueryDsl.ConditionlessWhen`1.<>c__DisplayClass2_0.<Add>b__0(QueryContainer q) in /home/runner/work/opensearch-net/opensearch-net/tests/Tests/QueryDsl/ConditionlessWhen.cs:line 44
2023-07-16T22:32:23.3847261Z    at Tests.QueryDsl.QueryDslUsageTestsBase.ConditionlessWhenExpectedToBe() in /home/runner/work/opensearch-net/opensearch-net/tests/Tests/QueryDsl/QueryDslUsageTestsBase.cs:line 117
2023-07-16T22:32:23.4322451Z [xUnit.net 00:00:08.93]     Tests.Aggregations.Metric.GeoCentroid.GeoCentroidNoResultsAggregationUsageTests.SerializesFluent [SKIP]
2023-07-16T22:32:23.4329992Z [xUnit.net 00:00:08.93]     Tests.Aggregations.Metric.GeoCentroid.GeoCentroidNoResultsAggregationUsageTests.HitsTheCorrectUrl [SKIP]
2023-07-16T22:32:23.4340521Z [xUnit.net 00:00:08.93]     Tests.Aggregations.Metric.GeoCentroid.GeoCentroidNoResultsAggregationUsageTests.UsesCorrectHttpMethod [SKIP]
2023-07-16T22:32:23.4348461Z [xUnit.net 00:00:08.93]     Tests.Aggregations.Metric.GeoCentroid.GeoCentroidNoResultsAggregationUsageTests.SerializesInitializer [SKIP]
2023-07-16T22:32:23.4439317Z   Skipped Tests.Aggregations.Metric.GeoCentroid.GeoCentroidNoResultsAggregationUsageTests.SerializesFluent [1 ms]
2023-07-16T22:32:23.4440881Z   Skipped Tests.Aggregations.Metric.GeoCentroid.GeoCentroidNoResultsAggregationUsageTests.HitsTheCorrectUrl [1 ms]
2023-07-16T22:32:23.4441946Z   Skipped Tests.Aggregations.Metric.GeoCentroid.GeoCentroidNoResultsAggregationUsageTests.UsesCorrectHttpMethod [1 ms]
2023-07-16T22:32:23.4442999Z   Skipped Tests.Aggregations.Metric.GeoCentroid.GeoCentroidNoResultsAggregationUsageTests.SerializesInitializer [1 ms]
2023-07-16T22:32:26.5247884Z [xUnit.net 00:00:12.02]     Tests.QueryDsl.BoolDsl.Operators.OrOperatorUsageTests.Or [FAIL]
2023-07-16T22:32:26.6097567Z   Failed Tests.QueryDsl.BoolDsl.Operators.OrOperatorUsageTests.Or [119 ms]
2023-07-16T22:32:26.6098315Z   Error Message:
2023-07-16T22:32:26.6098956Z    Expected b.Should to contain 2 item(s), but found 3: {
2023-07-16T22:32:26.6100267Z     OpenSearch.Client.QueryContainerDescriptor`1[[Tests.Domain.Project, Tests.Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=96c599bbe3e70f5d]]
2023-07-16T22:32:26.6101742Z     {
2023-07-16T22:32:26.6101961Z     }, 
2023-07-16T22:32:26.6102450Z     OpenSearch.Client.QueryContainerDescriptor`1[[Tests.Domain.Project, Tests.Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=96c599bbe3e70f5d]]
2023-07-16T22:32:26.6102899Z     {
2023-07-16T22:32:26.6103104Z     }, 
2023-07-16T22:32:26.6103549Z     OpenSearch.Client.QueryContainerDescriptor`1[[Tests.Domain.Project, Tests.Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=96c599bbe3e70f5d]]
2023-07-16T22:32:26.6103981Z     {
2023-07-16T22:32:26.6104181Z     }
2023-07-16T22:32:26.6104381Z }
2023-07-16T22:32:26.6104575Z .
2023-07-16T22:32:26.6104770Z   Stack Trace:
2023-07-16T22:32:26.6105162Z      at FluentAssertions.Execution.XUnit2TestFramework.Throw(String message)
2023-07-16T22:32:26.6105708Z    at FluentAssertions.Execution.TestFrameworkProvider.Throw(String message)
2023-07-16T22:32:26.6106303Z    at FluentAssertions.Execution.DefaultAssertionStrategy.HandleFailure(String message)
2023-07-16T22:32:26.6106892Z    at FluentAssertions.Execution.AssertionScope.FailWith(Func`1 failReasonFunc)
2023-07-16T22:32:26.6107645Z    at FluentAssertions.Execution.AssertionScope.FailWith(Func`1 failReasonFunc)
2023-07-16T22:32:26.6108198Z    at FluentAssertions.Execution.AssertionScope.FailWith(String message, Object[] args)
2023-07-16T22:32:26.6108834Z    at FluentAssertions.Collections.GenericCollectionAssertions`3.HaveCount(Int32 expected, String because, Object[] becauseArgs)
2023-07-16T22:32:26.6110115Z    at Tests.QueryDsl.BoolDsl.Operators.OrOperatorUsageTests.<>c.<Or>b__1_3(IBoolQuery b) in /home/runner/work/opensearch-net/opensearch-net/tests/Tests/QueryDsl/BoolDsl/Operators/OrOperatorUsageTests.cs:line 52
2023-07-16T22:32:26.6111337Z    at Tests.QueryDsl.BoolDsl.Operators.OperatorUsageBase.ReturnsBool(QueryContainer combined, Action`1 boolQueryAssert) in /home/runner/work/opensearch-net/opensearch-net/tests/Tests/QueryDsl/BoolDsl/Operators/OperatorUsageBase.cs:line 61
2023-07-16T22:32:26.6112835Z    at Tests.QueryDsl.BoolDsl.Operators.OperatorUsageBase.ReturnsBool(QueryContainer combined, Func`2 selector, Action`1 boolQueryAssert) in /home/runner/work/opensearch-net/opensearch-net/tests/Tests/QueryDsl/BoolDsl/Operators/OperatorUsageBase.cs:line 53
2023-07-16T22:32:26.6114007Z    at Tests.QueryDsl.BoolDsl.Operators.OrOperatorUsageTests.Or() in /home/runner/work/opensearch-net/opensearch-net/tests/Tests/QueryDsl/BoolDsl/Operators/OrOperatorUsageTests.cs:line 50
2023-07-16T22:32:27.4114779Z [xUnit.net 00:00:12.90]     Tests.QueryDsl.BoolDsl.Operators.AndOperatorUsageTests.And [FAIL]
2023-07-16T22:32:27.4115403Z   Failed Tests.QueryDsl.BoolDsl.Operators.AndOperatorUsageTests.And [56 ms]
2023-07-16T22:32:27.4122015Z   Error Message:
2023-07-16T22:32:27.4122739Z    Expected b.Must to contain 2 item(s), but found 3: {
2023-07-16T22:32:27.4123624Z     OpenSearch.Client.QueryContainerDescriptor`1[[Tests.Domain.Project, Tests.Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=96c599bbe3e70f5d]]
2023-07-16T22:32:27.4124494Z     {
2023-07-16T22:32:27.4125146Z     }, 
2023-07-16T22:32:27.4125714Z     OpenSearch.Client.QueryContainerDescriptor`1[[Tests.Domain.Project, Tests.Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=96c599bbe3e70f5d]]
2023-07-16T22:32:27.4126182Z     {
2023-07-16T22:32:27.4126382Z     }, 
2023-07-16T22:32:27.4126823Z     OpenSearch.Client.QueryContainerDescriptor`1[[Tests.Domain.Project, Tests.Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=96c599bbe3e70f5d]]
2023-07-16T22:32:27.4127245Z     {
2023-07-16T22:32:27.4127419Z     }
2023-07-16T22:32:27.4127612Z }
2023-07-16T22:32:27.4127796Z .
2023-07-16T22:32:27.4127996Z   Stack Trace:
2023-07-16T22:32:27.4128360Z      at FluentAssertions.Execution.XUnit2TestFramework.Throw(String message)
2023-07-16T22:32:27.4128856Z    at FluentAssertions.Execution.TestFrameworkProvider.Throw(String message)
2023-07-16T22:32:27.4130058Z    at FluentAssertions.Execution.DefaultAssertionStrategy.HandleFailure(String message)
2023-07-16T22:32:27.4130598Z    at FluentAssertions.Execution.AssertionScope.FailWith(Func`1 failReasonFunc)
2023-07-16T22:32:27.4131092Z    at FluentAssertions.Execution.AssertionScope.FailWith(Func`1 failReasonFunc)
2023-07-16T22:32:27.4131584Z    at FluentAssertions.Execution.AssertionScope.FailWith(String message, Object[] args)
2023-07-16T22:32:27.4132350Z    at FluentAssertions.Collections.GenericCollectionAssertions`3.HaveCount(Int32 expected, String because, Object[] becauseArgs)
2023-07-16T22:32:27.4133911Z    at Tests.QueryDsl.BoolDsl.Operators.AndOperatorUsageTests.<>c.<And>b__0_3(IBoolQuery b) in /home/runner/work/opensearch-net/opensearch-net/tests/Tests/QueryDsl/BoolDsl/Operators/AndOperatorUsageTests.cs:line 50
2023-07-16T22:32:27.4135331Z    at Tests.QueryDsl.BoolDsl.Operators.OperatorUsageBase.ReturnsBool(QueryContainer combined, Action`1 boolQueryAssert) in /home/runner/work/opensearch-net/opensearch-net/tests/Tests/QueryDsl/BoolDsl/Operators/OperatorUsageBase.cs:line 61
2023-07-16T22:32:27.4137742Z    at Tests.QueryDsl.BoolDsl.Operators.OperatorUsageBase.ReturnsBool(QueryContainer combined, Func`2 selector, Action`1 boolQueryAssert) in /home/runner/work/opensearch-net/opensearch-net/tests/Tests/QueryDsl/BoolDsl/Operators/OperatorUsageBase.cs:line 53
2023-07-16T22:32:27.4138894Z    at Tests.QueryDsl.BoolDsl.Operators.AndOperatorUsageTests.And() in /home/runner/work/opensearch-net/opensearch-net/tests/Tests/QueryDsl/BoolDsl/Operators/AndOperatorUsageTests.cs:line 48
2023-07-16T22:32:28.8303256Z [xUnit.net 00:00:14.32]     Tests.QueryDsl.BoolDsl.Operators.UnaryAddOperatorUsageTests.UnaryAdd [FAIL]
2023-07-16T22:32:28.8303982Z   Failed Tests.QueryDsl.BoolDsl.Operators.UnaryAddOperatorUsageTests.UnaryAdd [26 ms]
2023-07-16T22:32:28.8304414Z   Error Message:
2023-07-16T22:32:28.8304694Z    Expected b.Should to contain 2 item(s), but found 3: {
2023-07-16T22:32:28.8305205Z     OpenSearch.Client.QueryContainer
2023-07-16T22:32:28.8305901Z     {
2023-07-16T22:32:28.8306110Z     }, 
2023-07-16T22:32:28.8306537Z     OpenSearch.Client.QueryContainer
2023-07-16T22:32:28.8306971Z     {
2023-07-16T22:32:28.8307179Z     }, 
2023-07-16T22:32:28.8307442Z     OpenSearch.Client.QueryContainer
2023-07-16T22:32:28.8307720Z     {
2023-07-16T22:32:28.8307920Z     }
2023-07-16T22:32:28.8308101Z }
2023-07-16T22:32:28.8308472Z .
2023-07-16T22:32:28.8308690Z   Stack Trace:
2023-07-16T22:32:28.8309095Z      at FluentAssertions.Execution.XUnit2TestFramework.Throw(String message)
2023-07-16T22:32:28.8311841Z    at FluentAssertions.Execution.TestFrameworkProvider.Throw(String message)
2023-07-16T22:32:28.8312451Z    at FluentAssertions.Execution.DefaultAssertionStrategy.HandleFailure(String message)
2023-07-16T22:32:28.8313068Z    at FluentAssertions.Execution.AssertionScope.FailWith(Func`1 failReasonFunc)
2023-07-16T22:32:28.8313633Z    at FluentAssertions.Execution.AssertionScope.FailWith(Func`1 failReasonFunc)
2023-07-16T22:32:28.8314214Z    at FluentAssertions.Execution.AssertionScope.FailWith(String message, Object[] args)
2023-07-16T22:32:28.8315017Z    at FluentAssertions.Collections.GenericCollectionAssertions`3.HaveCount(Int32 expected, String because, Object[] becauseArgs)
2023-07-16T22:32:28.8316365Z    at Tests.QueryDsl.BoolDsl.Operators.UnaryAddOperatorUsageTests.<>c.<UnaryAdd>b__0_3(IBoolQuery b) in /home/runner/work/opensearch-net/opensearch-net/tests/Tests/QueryDsl/BoolDsl/Operators/UnaryAddOperatorUsageTests.cs:line 50
2023-07-16T22:32:28.8318173Z    at Tests.QueryDsl.BoolDsl.Operators.OperatorUsageBase.ReturnsBool(QueryContainer combined, Action`1 boolQueryAssert) in /home/runner/work/opensearch-net/opensearch-net/tests/Tests/QueryDsl/BoolDsl/Operators/OperatorUsageBase.cs:line 61
2023-07-16T22:32:28.8319755Z    at Tests.QueryDsl.BoolDsl.Operators.OperatorUsageBase.ReturnsBool(QueryContainer combined, Func`2 selector, Action`1 boolQueryAssert) in /home/runner/work/opensearch-net/opensearch-net/tests/Tests/QueryDsl/BoolDsl/Operators/OperatorUsageBase.cs:line 53
2023-07-16T22:32:28.8322055Z    at Tests.QueryDsl.BoolDsl.Operators.UnaryAddOperatorUsageTests.UnaryAdd() in /home/runner/work/opensearch-net/opensearch-net/tests/Tests/QueryDsl/BoolDsl/Operators/UnaryAddOperatorUsageTests.cs:line 48
2023-07-16T22:32:28.8457362Z [xUnit.net 00:00:14.34]     Tests.QueryDsl.BoolDsl.Operators.NotOperatorUsageTests.Not [FAIL]
2023-07-16T22:32:28.8754898Z   Failed Tests.QueryDsl.BoolDsl.Operators.NotOperatorUsageTests.Not [21 ms]
2023-07-16T22:32:28.8819468Z   Error Message:
2023-07-16T22:32:28.8841701Z    Expected b.Should to contain 2 item(s), but found 3: {
2023-07-16T22:32:28.8842523Z     OpenSearch.Client.QueryContainer
2023-07-16T22:32:28.8842933Z     {
2023-07-16T22:32:28.8843174Z     }, 
2023-07-16T22:32:28.8843653Z     OpenSearch.Client.QueryContainer
2023-07-16T22:32:28.8844047Z     {
2023-07-16T22:32:28.8844265Z     }, 
2023-07-16T22:32:28.8844554Z     OpenSearch.Client.QueryContainer
2023-07-16T22:32:28.8844939Z     {
2023-07-16T22:32:28.8845204Z     }
2023-07-16T22:32:28.8845411Z }
2023-07-16T22:32:28.8845597Z .
2023-07-16T22:32:28.8845927Z   Stack Trace:
2023-07-16T22:32:28.8846365Z      at FluentAssertions.Execution.XUnit2TestFramework.Throw(String message)
2023-07-16T22:32:28.8847373Z    at FluentAssertions.Execution.TestFrameworkProvider.Throw(String message)
2023-07-16T22:32:28.8848145Z    at FluentAssertions.Execution.DefaultAssertionStrategy.HandleFailure(String message)
2023-07-16T22:32:28.8848872Z    at FluentAssertions.Execution.AssertionScope.FailWith(Func`1 failReasonFunc)
2023-07-16T22:32:28.8849531Z    at FluentAssertions.Execution.AssertionScope.FailWith(Func`1 failReasonFunc)
2023-07-16T22:32:28.8850176Z    at FluentAssertions.Execution.AssertionScope.FailWith(String message, Object[] args)
2023-07-16T22:32:28.8850935Z    at FluentAssertions.Collections.GenericCollectionAssertions`3.HaveCount(Int32 expected, String because, Object[] becauseArgs)
2023-07-16T22:32:28.8852356Z    at Tests.QueryDsl.BoolDsl.Operators.NotOperatorUsageTests.<>c.<Not>b__0_3(IBoolQuery b) in /home/runner/work/opensearch-net/opensearch-net/tests/Tests/QueryDsl/BoolDsl/Operators/NotOperatorUsageTests.cs:line 50
2023-07-16T22:32:28.8853773Z    at Tests.QueryDsl.BoolDsl.Operators.OperatorUsageBase.ReturnsBool(QueryContainer combined, Action`1 boolQueryAssert) in /home/runner/work/opensearch-net/opensearch-net/tests/Tests/QueryDsl/BoolDsl/Operators/OperatorUsageBase.cs:line 61
2023-07-16T22:32:28.8855274Z    at Tests.QueryDsl.BoolDsl.Operators.OperatorUsageBase.ReturnsBool(QueryContainer combined, Func`2 selector, Action`1 boolQueryAssert) in /home/runner/work/opensearch-net/opensearch-net/tests/Tests/QueryDsl/BoolDsl/Operators/OperatorUsageBase.cs:line 53
2023-07-16T22:32:28.8859219Z    at Tests.QueryDsl.BoolDsl.Operators.NotOperatorUsageTests.Not() in /home/runner/work/opensearch-net/opensearch-net/tests/Tests/QueryDsl/BoolDsl/Operators/NotOperatorUsageTests.cs:line 48
2023-07-16T22:32:30.6235099Z [xUnit.net 00:00:16.12]     Tests.QueryDsl.Verbatim.StrictQueryUsageTests.FluentThrows [FAIL]
2023-07-16T22:32:30.6236612Z [xUnit.net 00:00:16.12]     Tests.QueryDsl.Verbatim.StrictQueryUsageTests.InitializerThrows [FAIL]
2023-07-16T22:32:30.6268552Z   Failed Tests.QueryDsl.Verbatim.StrictQueryUsageTests.FluentThrows [102 ms]
2023-07-16T22:32:30.6269487Z   Error Message:
2023-07-16T22:32:30.6270222Z    Assert.Throws() Failure
2023-07-16T22:32:30.6270652Z Expected: typeof(System.ArgumentException)
2023-07-16T22:32:30.6271023Z Actual:   (No exception was thrown)
2023-07-16T22:32:30.6271295Z   Stack Trace:
2023-07-16T22:32:30.6272527Z      at Tests.QueryDsl.Verbatim.StrictQueryUsageTests.FluentThrows() in /home/runner/work/opensearch-net/opensearch-net/tests/Tests/QueryDsl/Verbatim/VerbatimAndStrictQueryUsageTests.cs:line 266
2023-07-16T22:32:30.6273467Z   Failed Tests.QueryDsl.Verbatim.StrictQueryUsageTests.InitializerThrows [< 1 ms]
2023-07-16T22:32:30.6273901Z   Error Message:
2023-07-16T22:32:30.6274397Z    Assert.Throws() Failure
2023-07-16T22:32:30.6274740Z Expected: typeof(System.ArgumentException)
2023-07-16T22:32:30.6287657Z Actual:   (No exception was thrown)
2023-07-16T22:32:30.6288089Z   Stack Trace:
2023-07-16T22:32:30.6289023Z      at Tests.QueryDsl.Verbatim.StrictQueryUsageTests.InitializerThrows() in /home/runner/work/opensearch-net/opensearch-net/tests/Tests/QueryDsl/Verbatim/VerbatimAndStrictQueryUsageTests.cs:line 282
2023-07-16T22:32:37.0406910Z [xUnit.net 00:00:22.54]     Tests.Document.Multiple.BulkAll.BulkAllBadRetriesApiTests.Completes [SKIP]
2023-07-16T22:32:37.0914715Z   Skipped Tests.Document.Multiple.BulkAll.BulkAllBadRetriesApiTests.Completes [1 ms]
2023-07-16T22:32:37.7649918Z --------
2023-07-16T22:32:37.7650499Z Individual cluster running times:
2023-07-16T22:32:37.7650871Z --------
2023-07-16T22:32:37.7666005Z Failed collections:
2023-07-16T22:32:37.7673682Z  - ReadOnly: Tests.QueryDsl.Compound.Bool.BoolDslComplexQueryUsageTests
2023-07-16T22:32:37.7674606Z  - ReadOnly: Tests.QueryDsl.TermLevel.Prefix.PrefixQueryUsageTests
2023-07-16T22:32:37.7675467Z  - ReadOnly: Tests.QueryDsl.TermLevel.Term.TermQueryUsageTests
2023-07-16T22:32:37.7676171Z  - ReadOnly: Tests.QueryDsl.TermLevel.Term.TermQueryWithCaseInsensitiveUsageTests
2023-07-16T22:32:37.7677399Z  - ReadOnly: Tests.QueryDsl.TermLevel.Wildcard.WildcardQueryUsageTests
2023-07-16T22:32:37.7678548Z  - UNKNOWN: Tests.QueryDsl.BoolDsl.Operators.AndOperatorUsageTests
2023-07-16T22:32:37.7679167Z  - UNKNOWN: Tests.QueryDsl.BoolDsl.Operators.NotOperatorUsageTests
2023-07-16T22:32:37.7680108Z  - UNKNOWN: Tests.QueryDsl.BoolDsl.Operators.OrOperatorUsageTests
2023-07-16T22:32:37.7680780Z  - UNKNOWN: Tests.QueryDsl.BoolDsl.Operators.UnaryAddOperatorUsageTests
2023-07-16T22:32:37.7681436Z  - UNKNOWN: Tests.QueryDsl.Verbatim.StrictQueryUsageTests
2023-07-16T22:32:37.7682074Z ---Reproduce: -----
2023-07-16T22:32:37.7688418Z ./build.sh seed:6572 random:sourceserializer:false random:typedkeys:false random:httpcompression test "andoperator,notoperator,oroperator,unaryaddoperator,booldslcomplexquery,prefixquery,termquery,termquerywithcaseinsensitive,wildcardquery,strictquery"
2023-07-16T22:32:37.7689653Z --------
2023-07-16T22:32:37.8556187Z 
2023-07-16T22:32:37.8654271Z Failed!  - Failed:    11, Passed:  3086, Skipped:     5, Total:  3102, Duration: 20 s - /home/runner/work/opensearch-net/opensearch-net/tests/Tests/bin/Release/net6.0/Tests.dll (net6.0)

@david-alpert-nl
Copy link

Thank you for your response; running this command on main:

./build.sh seed:6572 random:sourceserializer:false random:typedkeys:false random:httpcompression test "andoperator,notoperator,oroperator,unaryaddoperator,booldslcomplexquery,prefixquery,termquery,termquerywithcaseinsensitive,wildcardquery,strictquery"

did give me a baseline green from which to test my change

:: test: Succeeded. (7.64 s)
:: ─────────────────────────────────────
:: Duration        Outcome    Target
:: ──────────────  ─────────  ──────────
:: 2 ms     0.0%   Succeeded  clean
:: 15 ms    0.1%   Succeeded  version
:: 1.90 s   8.9%   Succeeded  restore
:: 7.64 s   36.0%  Succeeded  test
:: 11.68 s  55.0%  Succeeded  full-build
:: ─────────────────────────────────────
:: Succeeded. (test) (21.2 s)

and based on that I will try adding some unit tests for my change in the style of this project, and also look to include updates for any tests which break as a result of this PR 👍

@davidalpert davidalpert force-pushed the GH-281-fluent-must-not-should-include-must_not-clause-in-search-request-body branch from 2caf7a2 to 75707a1 Compare July 17, 2023 16:53
@davidalpert davidalpert changed the title GH-281 TermQuery.IsConditionless with a string.Empty value should return false GH-281 TermQuery with a string.Empty value needs .Verbatim() or it is ignored as "conditionless" Jul 17, 2023
@davidalpert
Copy link
Contributor Author

@Xtansia I appreciate your prompt engagement with my issue and pull request.

I have now learned that a TermQuery with an empty string Value is seen as conditionless by design, and learned that the .Verbatim() clause lets me generate the request body that I need, including the conditionless TermQuery

I have updated this PR to revert my proposed change and simply add some unit tests documenting my investigation and discovery from GH-281.

Feel free to merge or close without merging these additional test cases.

@davidalpert davidalpert force-pushed the GH-281-fluent-must-not-should-include-must_not-clause-in-search-request-body branch from 75707a1 to 859b22f Compare July 17, 2023 21:48
tests/Tests.Reproduce/GitHubIssue281.cs Outdated Show resolved Hide resolved
tests/Tests.Reproduce/GitHubIssue281.cs Outdated Show resolved Hide resolved
…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]>
@davidalpert davidalpert force-pushed the GH-281-fluent-must-not-should-include-must_not-clause-in-search-request-body branch from 42db7ec to 64d94a2 Compare July 20, 2023 19:30
@davidalpert davidalpert requested a review from Xtansia July 20, 2023 19:31
@davidalpert
Copy link
Contributor Author

I have updated the PR description and added some examples to USAGE.md

Copy link
Collaborator

@Xtansia Xtansia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding to the USER_GUIDE, just had a comment on the example used

USER_GUIDE.md Outdated Show resolved Hide resolved
@davidalpert davidalpert force-pushed the GH-281-fluent-must-not-should-include-must_not-clause-in-search-request-body branch from 64d94a2 to c9a9e4e Compare August 11, 2023 00:22
@davidalpert davidalpert requested a review from Xtansia August 11, 2023 00:23
Copy link
Collaborator

@Xtansia Xtansia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, Thank you @davidalpert

Copy link
Collaborator

@Yury-Fridlyand Yury-Fridlyand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it work if a text field has non-keyword field? Or multiple fields?

@davidalpert
Copy link
Contributor Author

davidalpert commented Aug 11, 2023

@Yury-Fridlyand so far as I know the Verbatim property is the key to including clauses with empty values which might otherwise be considered as "empty" clauses and removed from the query serialization.

I am currently using this Verbatim approach on a keyword field but have found that pointing the clause at the core field or sub-field (like keyword) was a separate set of syntax from whether the empty value resulted in the clause getting included or excluded.

@Yury-Fridlyand
Copy link
Collaborator

I see. Thank you for the details!

@Xtansia Xtansia merged commit 9e9c503 into opensearch-project:main Aug 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TermQuery with empty string value is mistakenly treated as ConditionLess and excluded from search request body
4 participants