Home > OS >  How to GET a document from an index inside of an alias
How to GET a document from an index inside of an alias

Time:07-22

I have inserted a few of my indexes inside of an alias because I've updated the index mapping a few times. I am looking to query my indexes behind my alias for potential documents depending on the search criteria.

I've been querying using just indexes up until now, like so -

  const { body: clientBody } = await client.search({
    index: 'my-index',
    filter_path: 'hits.hits._source',
    body: { query: { bool: esObject } },
    size: 10000,
  });

but as I now have multiple indexes I wish to query inside of my alias I have created (my-alias) this no longer works as needed. I've tried replacing the index for alias but this does not work. Is there something I'm missing?

How I've added my indexes to my alias.

await client.indices.updateAliases(
{[
    {
      add: {
        index: 'my-index-1',
        alias: 'my-alias',
      },
    },
    {
      add: {
        index: 'my-index-2'
        alias: 'my-alias'
       },
     },
]});

CodePudding user response:

According to the nodejs package. The index will be used as the target, as we can see from here.

So the solution was to just change my index, and stop it pointing at 'my-index' but rather at 'my-alias' instead.

  const { body: clientBody } = await client.search({
    index: 'my-alias',
    filter_path: 'hits.hits._source',
    body: { query: { bool: esObject } },
    size: 10000,
  });
  • Related