# Automated indices and its fields tests

**URL:** <https://discuss.elastic.co/t/automated-indices-and-its-fields-tests/148291>\
**Category:** Kibana\
**Created:** [September 12, 2018, 10:05am UTC](https://discuss.elastic.co/t/automated-indices-and-its-fields-tests/148291 "2018-09-12T10:05:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexander\_Davis](https://avatars.discourse-cdn.com/v4/letter/a/bcef8e/32.png) [@Alexander\_Davis](https://discuss.elastic.co/u/Alexander_Davis)\
**Post date:** [September 12, 2018, 10:05am UTC](https://discuss.elastic.co/t/automated-indices-and-its-fields-tests/148291/1 "2018-09-12T10:05:55Z")

</div>

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/elasticsearch/reference/current/docs-get.html)  
[https://www.elastic.co/guide/en/kibana/current/console-kibana.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**

---

<div class="post-metadata">

**Author:** ![jbudz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jbudz/32/45922_2.png) [@jbudz](https://discuss.elastic.co/u/jbudz)\
**Post date:** [September 14, 2018, 3:10am UTC](https://discuss.elastic.co/t/automated-indices-and-its-fields-tests/148291/2 "2018-09-14T03:10:41Z")

</div>

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](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](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl.html)

An example of a search:

```auto
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:

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

'

```

---

<div class="post-metadata">

**Author:** ![Alexander\_Davis](https://avatars.discourse-cdn.com/v4/letter/a/bcef8e/32.png) [@Alexander\_Davis](https://discuss.elastic.co/u/Alexander_Davis)\
**Post date:** [October 1, 2018, 12:11pm UTC](https://discuss.elastic.co/t/automated-indices-and-its-fields-tests/148291/3 "2018-10-01T12:11:13Z")

</div>

@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!

---

<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:** [October 29, 2018, 12:11pm UTC](https://discuss.elastic.co/t/automated-indices-and-its-fields-tests/148291/4 "2018-10-29T12:11:17Z")

</div>

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