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

filters #76

Open
mschoch opened this issue Aug 19, 2014 · 8 comments
Open

filters #76

mschoch opened this issue Aug 19, 2014 · 8 comments

Comments

@mschoch
Copy link
Contributor

mschoch commented Aug 19, 2014

most queries should have a filter variant which returns the same results but omits scoring

then have top-level FilteredQuery which can embed any other Query, and combine it with filters

@mschoch mschoch added this to the 1.0 milestone Jun 26, 2016
@mschoch
Copy link
Contributor Author

mschoch commented Jun 26, 2016

Alternatively, instead of having filters, make the scorer configurable. Filters are just searches without scoring (that therefore can be more easily cached).

@mschoch
Copy link
Contributor Author

mschoch commented Jun 26, 2016

Actionable 1.0 task is to see if all queries/searchers can be make to use configurable scorer.

@rdzar
Copy link

rdzar commented Feb 12, 2017

If you could merge disjuncts into conjuncts somehow, filtering would be possible. Currently something like this doesn't seem to work but could solve this problem, as it is like a AND (.. OR ..).

It still allows scoring to be used in full.

  "query": {
    "must": {
      "conjuncts": [
        {
          "term": "1",
          "field": "entity"
        },
        {
          "disjuncts": [
            {
              "wildcard": "*q*",
              "field": "code"
            },
            {
              "wildcard": "*q*",
              "field": "name"
            },
            {
              "wildcard": "*q*",
              "field": "type"
            }
          ]
        }
      ]
    }
  }

@mschoch
Copy link
Contributor Author

mschoch commented Feb 12, 2017

Using conjunction and disjunction together should work fine. The particular structure you've shown doesn't work because in the boolean query, the must is just a list of things that must be satisfied (which fits with conjunction).

But, you can use conjunction and disjunction together without boolean queries, and do exactly what you described.

@rdzar
Copy link

rdzar commented Feb 12, 2017

That's an amazingly fast response! Thanks!

I've been trying to make this (from my perspective filtering) work for some hours now and having quite some difficult time to make it work. Based off your response it seems really normal to pass conjuncts and disjuncts together into {"query": {..}} if I'm understanding correctly?

I just tried this. But it still doesn't show conjuncts + disjuncts. The problem is that this does work, but.. applied sorting messes this up. I sort on the code, causing low-score items to popup in the sorted index at the top. Due to limit 25 you'll be missing score'd items. Sorting on score using -_score, code would cause the items to be sorted strangly, as the scores of all items are kinda the same but mostly different. (1.006, 1.07, 1.053 etc). If you would be able to push me into the right direction that would be great.

I thought this would be the filtering you're referring to in this issue :)

Tried:

  "query": {
    "conjuncts": [
      {
        "term": "1",
        "field": "entity"
      }
    ],
    "disjuncts": [
      {
        "wildcard": "*q*",
        "field": "code"
      },
      {
        "wildcard": "*q*",
        "field": "name"
      },
      {
        "wildcard": "*q*",
        "field": "type"
      }
    ]
  }

It seems to work, but with q it seems to add odd documents, I'm trying to understand why. But as I've been testing with q only, it seemed something was wrong. But with q* it shows perfect results.

@mschoch
Copy link
Contributor Author

mschoch commented Feb 12, 2017

So, filtering in the context of this issue has to do with restricting results, but not affecting the score. This is useful for eliminating things you don't want in your search results at all, and thus you don't really want to pay the extra cost for these clause to be part of the scoring.

As for the query you're trying to run, you don't want conjuncts and disjuncts at the same level. Think of them just like AND and OR, if you put them at the same level, there are precedence issues, so we just don't even support that. Instead group them like you would with parentheses. So:

(a OR b) AND (c OR d)

would become:

Conjunction Query of:
  Disjunction Query a,b
  Disjunction Query c,d

Always look at the Query that is echo'd back in the SearchResponse object. If it doesn't match what you sent in, it means that we didn't parse it the way you expected.

As for the sorting, if you sort on anything other than _score, they won't be ordered by score (sorry if that sounds obvious, but you mentioned that when sorting by code they were then out of order by score, which would be expected) I'm not exactly sure what behavior you're trying to get.

I'd recommend simplifying the problem. First focus on getting the query you want executed, and getting the results back that you expect. Then, once you're happy that you have the right results, then look at how you can adjust the sort to get them in the order you want. Hope this helps.

@heidawei
Copy link

where is configurable scorer for filter?I can't set it anyway

@mschoch
Copy link
Contributor Author

mschoch commented Jun 11, 2018

@heidawei scoring is not configurable at all today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants