Skip to content

Wrong query processing #1983

Closed
Closed
@azubanov

Description

@azubanov

NEST/Elasticsearch.Net version: 2

Elasticsearch version: 2

Query:

            var fDescriptor = new QueryContainerDescriptor<TestObj>();
            var esFilters = new List<QueryContainer>();

            esFilters.Add(fDescriptor.Term(f => f.Field(o => o.Title).Value("1")));

            var res = client.Search<TestObj>(s => s.Query(q =>
                fDescriptor.Bool(b => b.Must(esFilters.ToArray())) ||
                (
                    (
                        q.Term(f => f.Field(o => o.Title).Value("3")) ||
                        q.Term(f => f.Field(o => o.Title).Value("4"))
                    ) &&
                    (
                        (
                            q.Term(f => f.Field(o => o.Title).Value("5")) ||
                            q.Term(f => f.Field(o => o.Title).Value("6"))
                        ) &&
                        (
                            q.Term(f => f.Field(o => o.Title).Value("7")) ||
                            q.Term(f => f.Field(o => o.Title).Value("8"))
                        )
                    )
                )
                ));

Result json:

POST /indexname/testobj/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "bool": {
            "must": [
              {
                "term": {
                  "title": {
                    "value": "1"
                  }
                }
              }
            ]
          }
        },
        {
          "bool": {
            "should": [
              {
                "term": {
                  "title": {
                    "value": "3"
                  }
                }
              },
              {
                "term": {
                  "title": {
                    "value": "4"
                  }
                }
              },
              {
                "term": {
                  "title": {
                    "value": "5"
                  }
                }
              },
              {
                "term": {
                  "title": {
                    "value": "6"
                  }
                }
              },
              {
                "term": {
                  "title": {
                    "value": "7"
                  }
                }
              },
              {
                "term": {
                  "title": {
                    "value": "8"
                  }
                }
              }
            ]
          }
        }
      ]
    }
  }
}

Describe the issue:
wrong bool nesting. all conditions on the same level.

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