term vs terms filter

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

term vs terms filter

Matthias Johnson
I'm filtering on terms. it seems that there are 2 choices: term filter and terms filter.

In my case I have a list of terms displayed, from which the user can select to be filtered on. This works very well with the terms filter, since it have an array. Additionally, the terms filter does just fine with a single value in the array.

The terms filter also offers much in terms of flexibility for tweaking the execution mode and caching, which the term filter does not.

That makes me wonder about the term filter and where it should be used.

Are there any usage guidelines for one over the other? Seems that passing an array to terms would not be a lot different over building an array of term filters inside an *or* filter.

\@matthias

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/7336d8cc-0a6b-4094-969a-61c8de3bb2f1%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: term vs terms filter

Binh Ly
Mathias, you're correct in your observations. The only thing you might want to be aware of is the terms filter is automatically cached, whereas an or filter of many term filters is not automatically cached. But the results you will get back should be the same.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/4944f3bc-0ee5-4d07-ac27-801af53ed970%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: term vs terms filter

Matthias Johnson
Thanks Binh. Out of curiosity do you know of performance differences between the 2 choices? it would seem that the terms filter with it's caching may provide better performance?

\@matthias

On Friday, January 31, 2014 10:34:50 AM UTC-7, Binh Ly wrote:
Mathias, you're correct in your observations. The only thing you might want to be aware of is the terms filter is automatically cached, whereas an or filter of many term filters is not automatically cached. But the results you will get back should be the same.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/f2d6b901-d415-45fa-8687-4fb91a6d961b%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Reply | Threaded
Open this post in threaded view
|

Re: term vs terms filter

Binh Ly
Matthias,

For the terms filter, let's say you do:

{
  "query": {
    "filtered": {
      "filter": {
        "terms": {
          "a": [
            "a",
            "b"
          ]
        }
      }
    }
  }
}

If you run the above exact query many times, the succeeding calls will be faster since the first call will cache the result of the above filter.

The or filter is not cached by default (but you can cache it explicitly if needed) so if you run an or filter many times, it will re-evaluate for each succeeding call (unless you explicitly cache it).

This might help also:

http://www.elasticsearch.org/blog/all-about-elasticsearch-filter-bitsets/

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/8a112f6b-d310-44f8-84a5-c9df65e6a9f1%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.