# \[terms\_set\] query does not support \[minimum\_should\_match\_script\]

**URL:** https://discuss.elastic.co/t/terms-set-query-does-not-support-minimum-should-match-script/115732
**Category:** Elasticsearch
**Created:** [January 16, 2018, 2:33pm UTC](https://discuss.elastic.co/t/terms-set-query-does-not-support-minimum-should-match-script/115732 "2018-01-16T14:33:55Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![jchannon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jchannon/32/23280_2.png) [@jchannon](https://discuss.elastic.co/u/jchannon)
#### Post date: [January 16, 2018, 2:33pm UTC](https://discuss.elastic.co/t/terms-set-query-does-not-support-minimum-should-match-script/115732/1 "2018-01-16T14:33:56Z")

</div>

Copying the commands in this document and I get the error in the title when I login as a user and do a search. Anybody know why?

[https://www.elastic.co/blog/attribute-based-access-control-with-xpack?blade=tw&hulk=social](https://www.elastic.co/blog/attribute-based-access-control-with-xpack?blade=tw&hulk=social)

---

<div class="post-metadata">

### Author: ![jchannon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jchannon/32/23280_2.png) [@jchannon](https://discuss.elastic.co/u/jchannon)
#### Post date: [January 29, 2018, 3:59pm UTC](https://discuss.elastic.co/t/terms-set-query-does-not-support-minimum-should-match-script/115732/2 "2018-01-29T15:59:57Z")

</div>

To be more specific here's a screenshot:

 ![01](https://us1.discourse-cdn.com/elastic/original/3X/5/f/5faa06812867b0cfc409946a19bbabb5c5c8ed51.png)

This is on Elastic 6:1:2 and Kibana 6:1:2

---

<div class="post-metadata">

### Author: ![ESamir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/esamir/32/77283_2.png) [@ESamir](https://discuss.elastic.co/u/ESamir)
#### Post date: [January 29, 2018, 9:47pm UTC](https://discuss.elastic.co/t/terms-set-query-does-not-support-minimum-should-match-script/115732/5 "2018-01-29T21:47:25Z")

</div>

Hi

Can you try the following query and let me know if you still have any issues

```
GET /my-index/_search
{
"query": {
"terms_set": {
"security_attributes" : {
"terms" : ["living", "in a van", "down by the river"],
"minimum_should_match_script": {
"source": "params.num_terms"
}
}
}
}
}

```

Regards

---

<div class="post-metadata">

### Author: ![jchannon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jchannon/32/23280_2.png) [@jchannon](https://discuss.elastic.co/u/jchannon)
#### Post date: [January 29, 2018, 10:40pm UTC](https://discuss.elastic.co/t/terms-set-query-does-not-support-minimum-should-match-script/115732/6 "2018-01-29T22:40:53Z")

</div>

Works but doesn't return any documents

---

<div class="post-metadata">

### Author: ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)
#### Post date: [January 30, 2018, 11:24am UTC](https://discuss.elastic.co/t/terms-set-query-does-not-support-minimum-should-match-script/115732/7 "2018-01-30T11:24:33Z")

</div>

In addition to @ESamir's change to use `{ "source": "params.num_terms" }`, the blog post assumes that `security_attributes` is mapped as `keyword` data type. If the mapping has been inferred, the following query will work, using the `keyword` _sub-field (of a multi-field)_ on `security_attributes`

```json
GET my_index/_search
{
    "query": { 
        "terms_set": {
            "security_attributes.keyword": {
                "terms": ["living", "in a van", "down by the river"],
                "minimum_should_match_script": { 
                  "source": "params.num_terms" 
                }
            }            
        }
    }
}

```

which returns

```json
{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 0.8630463,
    "hits": [
      {
        "_index": "my_index",
        "_type": "doc",
        "_id": "1",
        "_score": 0.8630463,
        "_source": {
          "security_attributes": [
            "living",
            "in a van",
            "down by the river"
          ],
          "body": "you're not going to amount to jack squat"
        }
      }
    ]
  }
}

```

---

<div class="post-metadata">

### Author: ![jchannon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jchannon/32/23280_2.png) [@jchannon](https://discuss.elastic.co/u/jchannon)
#### Post date: [January 30, 2018, 1:19pm UTC](https://discuss.elastic.co/t/terms-set-query-does-not-support-minimum-should-match-script/115732/8 "2018-01-30T13:19:11Z")

</div>

Thanks to @forloop the following is what is required to get the demo working:

```
DELETE my_index

PUT my_index
{
    "mappings" : {
        "doc" : {
            "properties" : {
                "body" : { "type" : "text" },
                "security_attributes":{"type": "keyword"}
            }
        }
    }
}

PUT my_index/doc/1
{ 
    "security_attributes": ["living", "in a van", "down by the river"],
    "body": "you're not going to amount to jack squat"
}

PUT my_index/doc/2
{
    "security_attributes": ["living", "in a house", "down by the river"],
    "body": "keep calm, carry on"
}

GET my_index/_search
{
  "query": {
    "terms_set": {
      "security_attributes": {
        "terms": [
          "living",
          "in a van",
          "down by the river"
        ],
        "minimum_should_match_script": {
          "source": "params.num_terms"
        }
      }
    }
  }
}
```

---

<div class="post-metadata">

### Author: ![jchannon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jchannon/32/23280_2.png) [@jchannon](https://discuss.elastic.co/u/jchannon)
#### Post date: [January 30, 2018, 1:29pm UTC](https://discuss.elastic.co/t/terms-set-query-does-not-support-minimum-should-match-script/115732/9 "2018-01-30T13:29:53Z")

</div>

The Json for creating the users in that post is also incorrect, here's the correct version:

```
PUT _xpack/security/user/matt_foley
{
    "username": "matt_foley",
    "password":"password1",
    "roles": ["my_policy"],
    "full_name": "Matt Foley",
    "email": "mf@rivervan.com",
    "metadata": {
        "security_attributes": ["living", "in a van", "down by the river"]
    }
}
PUT _xpack/security/user/jack_black
{
    "username": "jack_black",
    "password":"password1",
    "roles": ["my_policy"],
    "full_name": "Jack Black",
    "email": "jb@tenaciousd.com",
    "metadata": {
        "security_attributes": ["living", "in a house", "down by the river"]
    }
}
```

---

<div class="post-metadata">

### Author: ![jchannon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jchannon/32/23280_2.png) [@jchannon](https://discuss.elastic.co/u/jchannon)
#### Post date: [January 30, 2018, 1:38pm UTC](https://discuss.elastic.co/t/terms-set-query-does-not-support-minimum-should-match-script/115732/10 "2018-01-30T13:38:41Z")

</div>

Oh and also the role json is wrong, the query should be

`{"template":{"source":"{\"bool\": {\"filter\": [{\"terms_set\": {\"security_attributes\": {\"terms\": {{#toJson}}_user.metadata.security_attributes{{/toJson}},\"minimum_should_match_script\": {\"source\":\"params.num_terms\"}}}}]}}"}}`

---

<div class="post-metadata">

### Author: ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)
#### Post date: [February 2, 2018, 11:01pm UTC](https://discuss.elastic.co/t/terms-set-query-does-not-support-minimum-should-match-script/115732/11 "2018-02-02T23:01:27Z")

</div>

Thanks @jchannon, the blog post has now been updated 👍

---

<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: [March 2, 2018, 11:01pm UTC](https://discuss.elastic.co/t/terms-set-query-does-not-support-minimum-should-match-script/115732/12 "2018-03-02T23:01:45Z")

</div>

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