# Filter on multiple indice

**URL:** <https://discuss.elastic.co/t/filter-on-multiple-indice/276042>\
**Category:** Elasticsearch\
**Created:** [June 15, 2021, 5:42pm UTC](https://discuss.elastic.co/t/filter-on-multiple-indice/276042 "2021-06-15T17:42:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dgastudio](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dgastudio/32/90362_2.png) [@dgastudio](https://discuss.elastic.co/u/dgastudio)\
**Post date:** [June 15, 2021, 5:42pm UTC](https://discuss.elastic.co/t/filter-on-multiple-indice/276042/1 "2021-06-15T17:42:03Z")

</div>

Hello.  
i have 2 indices, employee\_profile and employee\_shift

a need to create a page, on which one, i have to list all the employees with calendar of shifts for each one

right now, i'm doing a request to employee\_profile,employee\_shift/\_search, and, i'm getting both indices data

but the issue is coming when i'm trying to filter the data somehow.

based on suggestions from [Different filter on multiple indexes](https://discuss.elastic.co/t/different-filter-on-multiple-indexes/195151)  
i'm doing a following query

```auto
{
  "_source": [
    "uuid",
    "name",
    "ref_type",
    "date_from",
    "date_to"
  ],
  "aggs": {
    "name": {
      "terms": {
        "field": "name",
        "size": 10000
      }
    },
    "role": {
      "terms": {
        "field": "role",
        "size": 10000
      }
    },
    "pay_rate": {
      "terms": {
        "field": "pay_rate",
        "size": 10000
      }
    },
    "supervisor": {
      "terms": {
        "field": "supervisor",
        "size": 10000
      }
    },
    "type": {
      "terms": {
        "field": "ref_type",
        "size": 10000
      }
    }
  },
  "query": {
    "bool": {
      "must": [
        {
          "match_all": {
            
          }
        }
      ],
      "filter": [
        {
          "bool": {
            "must": {
              "term": {
                "_index": "employee_profile"
              }
            },
            "filter": {
              "bool": {
                "should": [
                  {
                    "term": {
                      "name": "bopruswacl"
                    }
                  }
                ]
              }
            }
          }
        }
      ]
    }
  },
  "sort": [
    {
      "created": "ASC"
    }
  ],
  "size": 10000
}

```

it's filtering fine on employee\_profile index, but it's excluding all the data from employee\_shift

it's possible somehow to apply filter to only one indice and show all hits from another indice if there are no filter for it?

thank you

---

<div class="post-metadata">

**Author:** ![dgastudio](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dgastudio/32/90362_2.png) [@dgastudio](https://discuss.elastic.co/u/dgastudio)\
**Post date:** [June 16, 2021, 10:00am UTC](https://discuss.elastic.co/t/filter-on-multiple-indice/276042/2 "2021-06-16T10:00:01Z")

</div>

fixed

```auto
$params = [
  'index' => 'employee_profile,employee_shift',
  'body' => [
    'query' => [
      'bool' => [
        'should' => [
          (object ) [
            'bool' => [
              'filter' => [
                'term' => ['_index' => 'employee_profile'],
              ],
              'must' => [
                'match' => ['name' => 'chetrap'],
              ],
            ],
          ],
          (object ) [
            'bool' => [
              'filter' => [
                'term' => ['_index' => 'employee_shift'],
              ],
            ],
          ],
        ],
      ],
    ],
  ],
];

```

---

<div class="post-metadata">

**Author:** ![Mik\_a](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mik_a/32/78256_2.png) [@Mik\_a](https://discuss.elastic.co/u/Mik_a)\
**Post date:** [June 16, 2021, 10:14am UTC](https://discuss.elastic.co/t/filter-on-multiple-indice/276042/3 "2021-06-16T10:14:17Z")

</div>

do you or someone know if this kind can be used in Kibana? how in that case? Fitering in kibana seem to be very limited

---

<div class="post-metadata">

**Author:** ![venkatesh\_prasanth](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/venkatesh_prasanth/32/89319_2.png) [@venkatesh\_prasanth](https://discuss.elastic.co/u/venkatesh_prasanth)\
**Post date:** [June 16, 2021, 10:31am UTC](https://discuss.elastic.co/t/filter-on-multiple-indice/276042/4 "2021-06-16T10:31:34Z")

</div>

you have to create mapping as per your index

---

<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 14, 2021, 10:31am UTC](https://discuss.elastic.co/t/filter-on-multiple-indice/276042/5 "2021-07-14T10:31:58Z")

</div>

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