Filter on multiple indice

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
i'm doing a following query

{
  "_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

fixed

$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'],
              ],
            ],
          ],
        ],
      ],
    ],
  ],
];

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

1 Like

you have to create mapping as per your index

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