# Help my please realized clarifying filtering

**URL:** <https://discuss.elastic.co/t/help-my-please-realized-clarifying-filtering/322385>\
**Category:** Elasticsearch\
**Created:** [January 3, 2023, 2:55pm UTC](https://discuss.elastic.co/t/help-my-please-realized-clarifying-filtering/322385 "2023-01-03T14:55:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Parano9I](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/parano9i/32/115497_2.png) [@Parano9I](https://discuss.elastic.co/u/Parano9I)\
**Post date:** [January 3, 2023, 2:55pm UTC](https://discuss.elastic.co/t/help-my-please-realized-clarifying-filtering/322385/1 "2023-01-03T14:55:01Z")

</div>

```auto
GET original_docs/_search
{
  "_source": [
    "styles",
    "production_date_start"
  ],
  "from": 20,
  "size": 20,
  "query": {
    "bool": {
      "filter": [
        {
          "nested": {
            "path": "styles",
            "query": {
              "terms": {
                "styles.name": [
                  "Gothic"
                ]
              }
            }
          }
        }
      ]
    }
  }
}

```

result

```auto
{
        "_index" : "original_docs",
        "_type" : "_doc",
        "_id" : "77",
        "_score" : 0.0,
        "_source" : {
          "production_date_start" : 1402,
          "styles" : [
            {
              "name" : "Gothic"
            },
            {
              "name" : "Renaissance"
            }
          ]
        }
      },

```

When I add another value

```auto
"terms": {
                "styles.name": [
                  "Gothic",
                 "Renaissance"
                ]
              }

```

So I need that as a result there were documents where the styles field necessarily contained ["Gothic","Renaissance"] or other fields ["Gothic","Renaissance" ...], now it doesn't work like that, the results are displayed where there are only "Gothic" or "Renaissance" and ["Gothic","Renaissance" ...] only 3 variants are needed.

---

<div class="post-metadata">

**Author:** ![Parano9I](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/parano9i/32/115497_2.png) [@Parano9I](https://discuss.elastic.co/u/Parano9I)\
**Post date:** [January 3, 2023, 2:59pm UTC](https://discuss.elastic.co/t/help-my-please-realized-clarifying-filtering/322385/2 "2023-01-03T14:59:05Z")

</div>

```auto
POST /_scripts/painless/_execute
{
  "script": {
    "source": "int matches=0; for(String item : params.haystack){if(params.finds.contains(item)){matches++}} if(params.finds.length === matches) return params.haystack",
    "params": {
      "finds": ["Gothic", "Northern Renaissance"],
      "haystack": ["Gothic", "Northern Renaissance", "Ottonian"]
    }
  }
}

```

This script fulfills my needs, but I can't add it to GET \_search, I have a problem with doc['styles.name'] there, for some reason it only returns one element.

---

<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:** [January 31, 2023, 2:59pm UTC](https://discuss.elastic.co/t/help-my-please-realized-clarifying-filtering/322385/3 "2023-01-31T14:59:28Z")

</div>

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