Skip to content
This repository was archived by the owner on Jul 2, 2024. It is now read-only.
This repository was archived by the owner on Jul 2, 2024. It is now read-only.

Don't use root level filter for search filters #71

Description

@pickypg

The current generation of queries that supply a Filter will result in a root level filter. For example, if you had:

query.Query(q => q.Number > 10).Where(q => q.State == "WA");

then this generates something along the lines of

{
  "query" : {
    "range" : {
      "Number" : {
        "gt" : 10
      }
    }
  },
  "filter" : {
    "term" : {
      "State" : "WA"
    }
  }
}

Note: it's not really useful to score a range query as it either matches or not, but that's not the point.

However, using the root-level filter is actually using something called Post Filter, which is a post processing filter. This is useful when you want to pass certain hits to facets/aggregations, but then you need to prune them from being returned within the overall response (a rare need). What you actually want is a filtered query that itself contains a filter and/or a query.

The above should become:

{
  "query" : {
    "filtered" : {
      "query" : {
        "Number" : {
          "range" : {
            "gt" : 10
          }
        }
      },
      "filter" : {
        "term" : {
          "State" : "WA"
        }
      }
    }
  }
}

This will perform the filter before any query (or hits being returned), which is when you want it to happen.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions