# Invalid Index Error in Elastic Search - querying against multiple indexes

**URL:** <https://discuss.elastic.co/t/invalid-index-error-in-elastic-search-querying-against-multiple-indexes/309462>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [July 12, 2022, 10:49pm UTC](https://discuss.elastic.co/t/invalid-index-error-in-elastic-search-querying-against-multiple-indexes/309462 "2022-07-12T22:49:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bigalbunayan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bigalbunayan/32/100717_2.png) [@bigalbunayan](https://discuss.elastic.co/u/bigalbunayan)\
**Post date:** [July 12, 2022, 10:49pm UTC](https://discuss.elastic.co/t/invalid-index-error-in-elastic-search-querying-against-multiple-indexes/309462/1 "2022-07-12T22:49:36Z")

</div>

When I run the below code I'm running the following in error in Elasticsearch:

`Invalid alias name [...] must not contain the following characters [, \", *, \\, <, |, ,, >, /, ?]`

It doesn't like that I'm using `index1,index2` as my index (I've also tried `index : [index1, index2]`

This code works in Kibana when I run it against the same data source.

Elasticsearch dependency is `"@elastic/elasticsearch": "7.6.1"`

```auto
const { client } = context; // context from graphql resolver

  const query = buildQuery({
    id: id,
    queryIndex: `${index1},${index2}`;
  });

  const results = await client.search(query);

  export const buildQuery = ({ id. queryIndex }) => ({
      index: queryIndex,
      body: {
        query: {
          bool: {
            must: [
              {
                terms: {
                  'someId': [id]
                }
              }
            ]
          }
        },
        aggs: {
          byindex: {
            terms: {
              field: '_index'
            },
            aggs: {
              min_date: {
                min: {
                  field: 'date',
                  format: 'yyyy-MM-dd'
                }
              },
              max_date: {
                max: {
                  field: 'date',
                  format: 'yyyy-MM-dd'
                }
              }
            }
          }
        }
      }
    });
    

```

---

<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:** [August 2, 2022, 6:50pm UTC](https://discuss.elastic.co/t/invalid-index-error-in-elastic-search-querying-against-multiple-indexes/309462/2 "2022-08-02T18:50:25Z")

</div>

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