# How to filter out elements from an array that doesn't match the query?

**URL:** <https://discuss.elastic.co/t/how-to-filter-out-elements-from-an-array-that-doesnt-match-the-query/29899>\
**Category:** Elasticsearch\
**Created:** [September 24, 2015, 7:49am UTC](https://discuss.elastic.co/t/how-to-filter-out-elements-from-an-array-that-doesnt-match-the-query/29899 "2015-09-24T07:49:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexander\_Skiller](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alexander_skiller/32/4697_2.png) [@Alexander\_Skiller](https://discuss.elastic.co/u/Alexander_Skiller)\
**Post date:** [September 24, 2015, 7:49am UTC](https://discuss.elastic.co/t/how-to-filter-out-elements-from-an-array-that-doesnt-match-the-query/29899/1 "2015-09-24T07:49:43Z")

</div>

Hi dear elasticsearch community,

Here is my index

```
POST /products
{
   "settings": {
      "analysis": {
         "filter": {
            "nGram_filter": {
               "type": "nGram",
               "min_gram": 2,
               "max_gram": 20,
               "token_chars": [
                  "letter",
                  "digit",
                  "punctuation",
                  "symbol"
               ]
            }
         },
         "analyzer": {
            "nGram_analyzer": {
               "type": "custom",
               "tokenizer": "whitespace",
               "filter": [
                  "lowercase",
                  "asciifolding",
                  "nGram_filter"
               ]
            }
         }
      }
   }
}

```

* * *

here is my mapping

```
POST /products/paramSuggestions/_mapping
{
   "properties": {
       "productName": {
          "type": "string"
       },
   "params": {
          "properties": {
             "paramName": {
                "type": "string",
                "analyzer": "nGram_analyzer"
             },
             "value": {
                "type": "string",
                "analyzer": "nGram_analyzer"
             }
          }
       }
   }
}

```

* * *

here is a sample product

```
POST /products/paramSuggestions/1
{
  "productName": "iphone 6",
  "params": [
    {
      "paramName": "color",
      "value": "white"
    },
    {
      "paramName": "capacity",
      "value": "32GB"
    }
  ]
}

```

* * *

here is a sample query to get the document by matching ngram parameter name

```
GET products/paramSuggestions/_search
{
   "size": 10,
   "query": {
      "filtered": {
         "query": {
            "match": {
               "paramName": {
                  "query": "col",
                  "operator": "and"
               }
            }
         }
      }
   }
}

```

* * *

here is the unwanted result of previous query

{

```
   "took": 2,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 1,
      "max_score": 0.33217794,
      "hits": [
         {
            "_index": "products",
            "_type": "paramSuggestions",
            "_id": "1",
            "_score": 0.33217794,
            "_source": {
               "productName": "iphone 6",
               "params": [
                  {
                     "paramName": "color",
                     "value": "white"
                  },
                  {
                     "paramName": "capacity",
                     "value": "32GB"
                  }
               ]
            }
         }
      ]
   }
}

```

here is the wanted result:

```
{
   "took": 2,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 1,
      "max_score": 0.33217794,
      "hits": [
         {
            "_index": "products",
            "_type": "paramSuggestions",
            "_id": "1",
            "_score": 0.33217794,
            "_source": {
               "productName": "iphone 6",
               "params": [
                  {
                     "paramName": "color",
                     "value": "white"
                  },
               ]
            }
         }
      ]
   }
}

```

So the question is, how should the GET query look like, so it returns the WANTED query?

Thank you very much for your time 😉

---

<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:** [July 5, 2017, 11:48pm UTC](https://discuss.elastic.co/t/how-to-filter-out-elements-from-an-array-that-doesnt-match-the-query/29899/2 "2017-07-05T23:48:18Z")

</div>


