# ES 2.0 terms filter with execution

**URL:** <https://discuss.elastic.co/t/es-2-0-terms-filter-with-execution/67781>\
**Category:** Elasticsearch\
**Created:** [December 1, 2016, 3:24pm UTC](https://discuss.elastic.co/t/es-2-0-terms-filter-with-execution/67781 "2016-12-01T15:24:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Linus\_Pettersson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/linus_pettersson/32/1107_2.png) [@Linus\_Pettersson](https://discuss.elastic.co/u/Linus_Pettersson)\
**Post date:** [December 1, 2016, 3:24pm UTC](https://discuss.elastic.co/t/es-2-0-terms-filter-with-execution/67781/1 "2016-12-01T15:24:51Z")

</div>

Hi!

I have articles (and a bunch of other stuff) with tags. In my search I aggregate these tags and provide them as filters. Previously I could use a terms filter with execution `and` to make it filter on _all_ selected tags. It looked like this (a bit simplified):

```auto
  {
    :body=>
    { :query=>
      { :filtered=>
        { :query=>
          {
            :multi_match=>
            {
              :query=> "Something",
              :fields=> ["*.original^4", "*.stemmed", "*.partial", "tag.name.original^30", "tag.name.lowercased^30", "department.title", "department_title", "colleague.full_name"],
              :cutoff_frequency=>0.001
            }
          },
          :filter=>
          {
            :terms=> {"tags.id"=> [5, 8], :execution=>:and }
          }
        }
      },
      :aggregations=>
      {
        :tag_ids=>
        {
          :terms=>
          {
            :field=>"tags.id"
          }
        }
      },
      :_source=> ["id"],
      :from=>0, :size=>10
    }, :index=>["my_index"], :type=>[]
  }

```

However, now that I'm trying to use ES 2.0 instead of 1.X the tag id filter does not work anymore. The `execution` part is ignored and it always matches on _any_ of the specified ids instead of on all of them.

It seems this functionality was "esoteric" enough to have it removed: [https://github.com/elastic/elasticsearch/pull/10531/files#diff-45578110da805e8e218ec718a8351525L52](https://github.com/elastic/elasticsearch/pull/10531/files#diff-45578110da805e8e218ec718a8351525L52)

However, I can't find any other way of doing this kind of filtering.

Does anyone have an idea on how to get this filter working on ES 2.0?

EDIT:

Also, the tags are indexed nested on the articles.

```auto
{
  title,
  body,
 ....
  tags: [
    {
       1.
       SomeTag
    },
    {
       2,
       AnotherTag
     }
  ]
}

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 29, 2016, 3:25pm UTC](https://discuss.elastic.co/t/es-2-0-terms-filter-with-execution/67781/2 "2016-12-29T15:25:10Z")

</div>

Closed on December 29, 2016, 3:25pm UTC

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
