Evan Brittain
Evan Brittain

Reputation: 587

How to find what index a field belongs to in elasticsearch?

I am new to elasticsearch. I have to write a query using a given field but I don't know how to find the appropriate index. How would I find this information?

Upvotes: 0

Views: 879

Answers (2)

apt-get_install_skill
apt-get_install_skill

Reputation: 2908

Another, more visual way to do that is through the kibana Index Management UI (assuming you have privileges to access the site).

There you can click on the indices and open the mappings tab to get all fields of the particular index. Then just search for the desired field.

Summary:

@Polynomial Proton's answer is the way of choice in 90% of the time. I just wanted to show you another way to solve your issue. It will require more manual steps than @Polynomial Proton's answer. Also, if you have a large amount of indices this way is not appropriate.

Upvotes: 1

Polynomial Proton
Polynomial Proton

Reputation: 5135

Edit:

Here's an easier/better way using mapping API

GET _mapping/field/<fieldname>

One of the ways you can find is to get records where the field exist

Replace the <fieldName> with your fields name. /_search will search across all indices and return any document that matches or has the field. Set _source to false, since you dont care about document contents but only index name.

GET /_search
{
  "_source": false, 
  "query": {
    "exists": {
      "field": "<fieldName>"
    }
  }
}

Upvotes: 1

Related Questions