# Filter by field for specific index on multi index query

**URL:** <https://discuss.elastic.co/t/filter-by-field-for-specific-index-on-multi-index-query/236545>\
**Category:** Elasticsearch\
**Created:** [June 10, 2020, 4:09pm UTC](https://discuss.elastic.co/t/filter-by-field-for-specific-index-on-multi-index-query/236545 "2020-06-10T16:09:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![alex-1](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@alex-1](https://discuss.elastic.co/u/alex-1)\
**Post date:** [June 10, 2020, 4:09pm UTC](https://discuss.elastic.co/t/filter-by-field-for-specific-index-on-multi-index-query/236545/1 "2020-06-10T16:09:22Z")

</div>

I've got two indexes which i can search on but wan't to filter by a field on one index and not the other.

e.g.

| Index1 | Index2 |
| --- | --- |
| _content_ | _content_ |
| _parent_ | _parent_ |
| ... | ... |

They share some common mappings.

I want to search in **content** but if the match is also in **index 2** then filter by the **parent** field in that index.

I thought I might have been able to use _script_ in the filter but I don't think _\_index_ is accessible in _\_doc_

```php
[
  'script' => [
    'script' => [
      'source' => 'doc[\'_index\'] == \'index2\' ? (doc[\'parent\'] == 1) : true',
      'lang' => 'painless'
    ]
  ]
]

```

Is something like this possible?

---

<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 8, 2020, 4:09pm UTC](https://discuss.elastic.co/t/filter-by-field-for-specific-index-on-multi-index-query/236545/2 "2020-07-08T16:09:22Z")

</div>

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