---
# System prepended metadata

title: ElasticSearch
tags: [elasticsearch, support]

---

# ElasticSearch

###### tags:`support` `elasticsearch`

## Ports

### Automate 1

Direct ES Port: 9200
ES Gateway Port: 8080

```bash
export ES_PORT=9200
```

### Automate 2

Direct ES Port: 10141
ES Gateway Port: 10144

```bash
export ES_PORT=10144
```

## Common commands

### Getting more info about ES indices

```bash
# General health
curl -s http://localhost:10144/_cat/health?v

# Index list
curl http://localhost:$ES_PORT/_cat/indices?v
```

### Deleting specific indices

```bash
curl -XDELETE http://localhost:$ES_PORT/$INDEX
```

### Fix failed shard allocations

```bash
# see the current status
curl -XGET localhost:$ES_PORT/_cluster/allocation/explain?pretty
# find the failed shards and why
curl -XGET localhost:$ES_PORT/_cat/shards?h=index,shard,prirep,state,unassigned.reason| grep UNASSIGNED
# force a flush of the state
INDEX=insights-2018.06.03 curl -XPOST localhost:$ES_PORT/$INDEX/_flush?force
# reroute failed shards
curl -XPOST localhost:$ES_PORT/_cluster/reroute?retry_failed
```

### Get all results

```bash
INDEX=compliance-latest-1 curl -XGET 'localhost:$ES_PORT/$INDEX/_search?size=5000' -d '
{
"query" : {
    "match_all" : {}
  }
}' > es_results.json
```

### Check disk usage

Check the current disk usage for all nodes in the cluster

```bash
curl -XGET 'localhost:$ES_PORT/_cat/allocation?v&pretty'
```

## Automate 1

### Create elastic search lock

This may be needed if you see an error in the reaper similiar to 

> 2017-10-29T20:45:02-05:00] ERROR: Elasticsearch lock index not created. Please run 'automate-ctl reconfigure'

Create the lock!
1. `curl -XPUT 'http://localhost:8080/elasticsearch/.locky'`
2. `automate-ctl reconfigure`

### Check for the health of indexes

```bash
curl -XGET 'http://localhost:9200/_cat/health?v'
```

### Check ES Snapshots

**TODO:** Add similar section for Automate 2

```bash
curl -XGET "http://localhost:8080/elasticsearch/_snapshot/_all?pretty"
curl -XGET "http://localhost:8080/elasticsearch/_snapshot/fs-chef-automate?pretty"
```

See all individual snapshots for the fs-chef-automate snapshots

```bash
curl -XGET "http://localhost:8080/elasticsearch/_snapshot/fs-chef-automate/_all?pretty"
```

### Max Fields

```bash
curl -XPUT ' http://localhost:9200/_all/_settings?preserve_existing=true'  -d '{ "index.mapping.total_fields.limit" : "100000" }'
```


## Automate 2

### read-only indexes

Remove the readonly flags for indexes

```bash
curl -XPUT -H "Content-Type: application/json" http://127.0.0.1:10144/_all/_settings -d '{"index.blocks.read_only_allow_delete": null}'
```


