# Getting "parsing\_exception","reason":"\[terms\] unknown token \[END\_ARRAY\] trying to do multiple field filter

**URL:** <https://discuss.elastic.co/t/getting-parsing-exception-reason-terms-unknown-token-end-array-trying-to-do-multiple-field-filter/82489>\
**Category:** Elasticsearch\
**Created:** [April 15, 2017, 11:43pm UTC](https://discuss.elastic.co/t/getting-parsing-exception-reason-terms-unknown-token-end-array-trying-to-do-multiple-field-filter/82489 "2017-04-15T23:43:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jerolomy](https://avatars.discourse-cdn.com/v4/letter/j/a6a055/32.png) [@jerolomy](https://discuss.elastic.co/u/jerolomy)\
**Post date:** [April 15, 2017, 11:43pm UTC](https://discuss.elastic.co/t/getting-parsing-exception-reason-terms-unknown-token-end-array-trying-to-do-multiple-field-filter/82489/1 "2017-04-15T23:43:08Z")

</div>

I would like to create a query which matches based on a phrase query but also filters based off of multiple fields. I am using PHP API syntax, but its pretty obvious how to translate the syntax. This is my query:

```
$searchParams = [
    'index' => 'main_search',
    'type' => 'my_type',
    'explain' => false,
    'body' => [
        'from' => $offset,
        'size' => $perPage * 2,
        'query' => [
            'function_score' => [
                'query' => [
                    'bool' => [
                        'filter' =>[
                            'bool' =>[
                                'must' => [
                                    ['terms' => ['price' => $price]],
                                    ['terms' => ['media_type' => $mediaType]],
                                ]
                            ]
                        ],
                        'should' => [
                            'multi_match' => [
                                'query' => $query,
                                'type' => 'most_fields',
                                'fields' => ['author','category','title', 'tag_name_list', 'tag_name_list^3', 'title.stemmed', 'title.shingles', 'title.autocomplete', 'tag_name_list.stemmed^3', 'tag_name_list.shingles^3'],
                            ]
                        ]
                    ]
                ],
                'script_score' => [
                    'script' => [
                        'lang' => 'painless',
                        'inline' => "
                                    double avgRating = (doc['num_ratings'].value == 0) ? 2 : doc['avg_rating'].value;
                                    long numRatings = (doc['num_ratings'].value == null) ? 0 : doc['num_ratings'].value;
                                    double rating = ((numRatings * 2.0/(numRatings + 2.0)) * avgRating) + ((2.0/(numRatings + 2.0)) * 2.0);
                                    rating * _score"
                    ]
                ]
            ],
        ]
    ]
];

```

When I was using one filter (without the bool inside of the filter) it was working. Now it is not. The input $mediaType variable and the $price variable are arrays of values that I want to filter by. Anyone know why I am getting "parsing\_exception","reason":"[terms] unknown token [END\_ARRAY] trying to do multiple field filter after [media\_type] ?

---

<div class="post-metadata">

**Author:** ![jerolomy](https://avatars.discourse-cdn.com/v4/letter/j/a6a055/32.png) [@jerolomy](https://discuss.elastic.co/u/jerolomy)\
**Post date:** [April 17, 2017, 3:42pm UTC](https://discuss.elastic.co/t/getting-parsing-exception-reason-terms-unknown-token-end-array-trying-to-do-multiple-field-filter/82489/2 "2017-04-17T15:42:49Z")

</div>

Its because $mediaType was wrapped in another array. So it was [[0 =\> val1, 1 =\> val2, 2 =\> val3]] instead of [0 =\> val1, 1 =\> val2, 2 =\> val3]

---

<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:** [May 15, 2017, 3:44pm UTC](https://discuss.elastic.co/t/getting-parsing-exception-reason-terms-unknown-token-end-array-trying-to-do-multiple-field-filter/82489/3 "2017-05-15T15:44:28Z")

</div>

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