Skip to content

Boolean and "conditionless" queries #1709

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

Closed
andersosthus opened this issue Jan 11, 2016 · 1 comment
Closed

Boolean and "conditionless" queries #1709

andersosthus opened this issue Jan 11, 2016 · 1 comment
Milestone

Comments

@andersosthus
Copy link
Contributor

Hi,

Been trying out NEST 2.0.0-Alpha 1 and I think there are some changes that could be important do document. If you try to add something to a boolean that's not "complete", it's not added. This is a bit different to the NEST 1.x behaviour.

Example:

var oldNest = new SearchDescriptor<TestObject>()
    .Index("index")
    .Type("type")
    .Query(q => q
        .Bool(b => b
            .Must(m => m.MatchAll())
            .Should(s => s
                .Fuzzy(f => f
                    .Field("name")
                    .Value("testvalue")))));

Produces in NEST 1.7.1:

{
  "query": {
    "bool": {
      "must": [
        {
          "match_all": {}
        }
      ],
      "should": [
        {
          "fuzzy": {
            "name": {
              "value": "testvalue"
            }
          }
        }
      ]
    }
  }
}

But in NEST 2.0.0 Alpha 1, it produces:

{
  "query": {
    "bool": {
      "must": [
        {
          "match_all": {}
        }
      ]
    }
  }
}

If you then change it to be the following:

var newNest = new SearchDescriptor<TestObject>()
    .Index("index")
    .Type("type")
    .Query(q => q
        .Bool(b => b
            .Must(m => m.MatchAll())
            .Should(s => s
                .Fuzzy(f => f
                    .Field("name")
                    .Value("testvalue")
                    .Fuzziness(Fuzziness.Auto)))));

it produces the expected output in NEST 2.0.0 Alpha 1:

{
  "query": {
    "bool": {
      "must": [
        {
          "match_all": {}
        }
      ],
      "should": [
        {
          "fuzzy": {
            "name": {
              "value": "testvalue",
              "fuzziness": "AUTO"
            }
          }
        }
      ]
    }
  }
}

This seems to apply to QueryStringas well (the DefaultField must be set). I have not checked any of the other queries.

@gmarz gmarz added Bug labels Jan 11, 2016
@gmarz
Copy link
Contributor

gmarz commented Jan 11, 2016

This looks like a bug actually. The conditionless behavior is kicking in because fuzziness isn't set (https://github.com/elastic/elasticsearch-net/blob/master/src/Nest/QueryDsl/TermLevel/Fuzzy/FuzzyQueryBase.cs#L33), but fuzziness is an optional parameter.

We may need to re-validate all of the IsConditionless states for the next release.

@gmarz gmarz closed this as completed in 4d20a3f Jan 11, 2016
gmarz added a commit that referenced this issue Jan 11, 2016
fix #1709 did a pass over all conditionless checks and fixed those th…
@gmarz gmarz added this to the 2.0.0 RC milestone Jan 14, 2016
@gmarz gmarz modified the milestones: 2.0.0-alpha2, 2.0.0 Jan 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants