Searching spesific alias using ElesticSearch

I need to search my ElasticSearch indexes using alias.

I see there is a few comments on the forum about searching spesific index by including the index name to search in the query like below example. This will not work using alias and this will not target the index directly, so it's not a good way to do the search.

 "query": {
    "bool": {
      "must": [
        {
          "term": {
            "_index": {
              "value": "myindexname"
            }
          }
        },

The preffered way would be to add the index or alias name in the URL like the example below. This will only search the selected alias. But I can't find any way to add this my-alias value.

If this is not possible it should be very easy for retool to add this functionality. The only thing needed is a textfield in the datasource page for indexname and if this is filled out it's added in the URL.

Does anyone has a working solution for this??

curl -X POST "http://localhost:9200/my-alias/_search" -H "Content-Type: application/json" -d '{
  "query": {
    "match": {
      "status": "error"
    }
  }
}'

Hi @eirik.andersen,

I may not be understanding correctly, but aren't you able to dynamically build the url in the app query?

You would have http://localhost:9200/ as the end point, and in your query you can add {{textInput1.value}}}/_search

if textInput1.value is not always available, then you can dynamically build the url in a transformer and make reference to it in your query.

Thanks for your reply.

when I create a Elastic query in retool I can choose the Resource and Method and add a Query as shown in the picture below. When selecting search as method this is added to the query string by retool before the query. So it's not possible to add the alias name to the query field.

The should be a textfield named Index/Alias between Resource and Method where the user could add the index to be searched as in the picture below.

Ah yeah, I see what you mean.

As a workaround, you could create a Rest API resource rather than the out of the box elastic resourcec. That will give you more flexibility around the endpoint and parameters you can add.

Thanks @MiguelOrtiz , that worked :slight_smile:

1 Like