Automated indices and its fields tests

Hello!
Sorry in advance if this question has been already asked.
But reading the official documentation did not help me:
https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html
https://www.elastic.co/guide/en/kibana/current/console-kibana.html
I would like to test indices, its fields, number of records in it

So, the goal:
Automatically check indices and its fields on right records and its quantity to run it locally or putting in into CI. Preferably using Javascript.

I see that it's possible to do via Elastic REST API but can't figure out how to construct a request.

I have {url} EC2 instance where elastic is being laid.
There exists:
Index: persons
fields: capacity, address

I want to make a request to retrieve number of records from capacity and address

There's a few parts here, I would start with pulling down the javascript client:
https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/index.html

In addition to that we'll need to construct a query for elasticsearch. The querying docs can be found in the elasticsearch section - https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl.html

An example of a search:

curl -X GET "localhost:9200/persons/_search" -H 'Content-Type: application/json' -d'
{
    "query": {
        "match_all": {}
    }
}
'

This is saying search all documents in my persons index.

And for example if you want to make sure the fields capacity and address exist:

curl -X GET "localhost:9200/persons/_search" -H 'Content-Type: application/json' -d'
{
  "query": {
    "bool": {
      "should":[
        { "exists": { "field": "capacity" } },
        { "exists": { "field": "address" } }
      ]
    }
  }
}

'

1 Like

@jbudz Hi. Sorry for long-term answer delay. I have read it, but did not have time to proceed the information and try something with it.
Got, I will try to figure out with this all.
Thank you!

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