Skip to content

Boolean and "conditionless" queries #1709

Closed
@andersosthus

Description

@andersosthus

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions