# After putting index setting, cannot add document

**URL:** <https://discuss.elastic.co/t/after-putting-index-setting-cannot-add-document/177311>\
**Category:** Elasticsearch\
**Created:** [April 17, 2019, 2:06pm UTC](https://discuss.elastic.co/t/after-putting-index-setting-cannot-add-document/177311 "2019-04-17T14:06:07Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![lemon\_soft](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lemon_soft/32/43072_2.png) [@lemon\_soft](https://discuss.elastic.co/u/lemon_soft)\
**Post date:** [April 17, 2019, 2:06pm UTC](https://discuss.elastic.co/t/after-putting-index-setting-cannot-add-document/177311/1 "2019-04-17T14:06:07Z")

</div>

I failed to create my ElasticSearch index, again. Here are my steps:

- created index with name clef2018, number of shard=1, number of replicas=0
- closed index
- put settings of clef2018 ([website](https://clefehealth.imag.fr/?page_id=28))
- put mappings of clef2018 ([website](https://clefehealth.imag.fr/?page_id=28))
- opened index
- checked that no document indexed
- cannot added document with bulk API or python
- also search failed

Is it an ElasticSearch issue? My python script is:

```
from elasticsearch import Elasticsearch
title="title"
body="body"
es = Elasticsearch([{"host": "10.0.0.1", "port": 9200}])
contentt = {'content': title +"\n"+ body}
res = ""
idd=idd+1
try:
	res = es.index(index='clef2018', doc_type='_doc', id=idd, body=contentt)
except:
	print("error:" + str(res))

```

Error is:

```
{
    "error": {
        "root_cause": [
            {
                "type": "unavailable_shards_exception",
                "reason": "[example][0] primary shard is not active Timeout: [1m], request: [BulkShardRequest [[example][0]] containing [index {[example][_doc][1], source[{\n \"content\": \"Hello world\"\n}]}]]"
            }
        ],
        "type": "unavailable_shards_exception",
        "reason": "[example][0] primary shard is not active Timeout: [1m], request: [BulkShardRequest [[example][0]] containing [index {[example][_doc][1], source[{\n \"content\": \"Hello world\"\n}]}]]"
    },
    "status": 503
}
```

---

<div class="post-metadata">

**Author:** ![gabriel\_tessier](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gabriel_tessier/32/27911_2.png) [@gabriel\_tessier](https://discuss.elastic.co/u/gabriel_tessier)\
**Post date:** [April 18, 2019, 1:55am UTC](https://discuss.elastic.co/t/after-putting-index-setting-cannot-add-document/177311/2 "2019-04-18T01:55:25Z")

</div>

Hi,  
you don't need to close the index to put settings and mapping.

Here the documentation about how to create an index and set settings and mapping: [https://www.elastic.co/guide/en/elasticsearch/reference/7.0/indices-create-index.html](https://www.elastic.co/guide/en/elasticsearch/reference/7.0/indices-create-index.html)

Can you first try with curl something like to add a document:

```
curl -XPOST 10.0.0.1:9200/clef2018/_doc/1 -d '{"content": "some content"}'

```

You're suppose to get your indexed document with curl -XGET 10.0.0.1:9200/clef2018/\_doc/1

If it's work it mean that elastic is ok and there's a problem with your script but so far it look correct.

When you write "checked that no document indexed" how do you check?

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [April 18, 2019, 5:16am UTC](https://discuss.elastic.co/t/after-putting-index-setting-cannot-add-document/177311/3 "2019-04-18T05:16:53Z")

</div>

> `[example][0] primary shard is not active`

I think this means your cluster health will be `red`. Here is an article about how to work out why:

> **[RED Elasticsearch Cluster? Panic no longer](https://www.elastic.co/blog/red-elasticsearch-cluster-panic-no-longer)**
>
> Your cluster is RED - you have unassigned shards and your cluster is not fully operational. Introducing a new Elasticsearch API which will save the day.

---

<div class="post-metadata">

**Author:** ![lemon\_soft](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lemon_soft/32/43072_2.png) [@lemon\_soft](https://discuss.elastic.co/u/lemon_soft)\
**Post date:** [April 18, 2019, 7:40am UTC](https://discuss.elastic.co/t/after-putting-index-setting-cannot-add-document/177311/4 "2019-04-18T07:40:15Z")

</div>

Hi,  
Thank you for your reply. I followed your comment and instructions, now indexing is ok. I gave settings while creating index. I fixed a little problem in mapping string. Settings and mappings are succeeded:

> {"settings":{"number\_of\_shards":1,"number\_of\_replicas":0,"analysis":{"analyzer":{"my\_english":{"tokenizer":"standard","filter":["lowercase","terrier\_stopwords","porter\_stem"]}},"filter":{"terrier\_stopwords":{"type":"stop","stopwords\_path":"stopwords/terrier-stop.txt"}}},"similarity":{"bm25\_content":{"type":"BM25","b":0.75,"k1":1.2}}},"mappings":{"docType":{"\_source":{"enabled":true},"properties":{"content":{"type":"text","similarity":"bm25\_content","analyzer":"my\_english"},"is\_html":{"type":"boolean"}}}}}

> {"acknowledged":true,"shards\_acknowledged":true,"index":"clef2018"}

I added doc with id=1. I checked "count" and saw nothing:

> curl [http://10.0.0.1:9200/clef2018/\_doc/\_count](http://10.0.0.1:9200/clef2018/_doc/_count)

> {"count":0,"\_shards":{"total":1,"successful":1,"skipped":0,"failed":0}}

The result showed id=1 is stored:

> curl -XGET 10.0.0.1:9200/clef2018/\_doc/1

> {"\_index":"clef2018","\_type":"\_doc","\_id":"1","\_version":9,"\_seq\_no":74,"\_primary\_term":2,"found":true,"\_source":{ "content": "Hello world"}}

Search returned _nothing_ ☹

> curl [http://10.0.0.1:9200/clef2018/\_doc/\_search?pretty=true](http://10.0.0.1:9200/clef2018/_doc/_search?pretty=true)

> { "took" : 0, "timed\_out" : false, "\_shards" : { "total" : 1, "successful" : 1, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : 0, "max\_score" : null, "hits" : [] } }

What should I check?  
Thanks.

---

<div class="post-metadata">

**Author:** ![gabriel\_tessier](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gabriel_tessier/32/27911_2.png) [@gabriel\_tessier](https://discuss.elastic.co/u/gabriel_tessier)\
**Post date:** [April 18, 2019, 8:58am UTC](https://discuss.elastic.co/t/after-putting-index-setting-cannot-add-document/177311/5 "2019-04-18T08:58:46Z")

</div>

Hi,

Do you launch your command from a script?  
If so you can add a refresh call after index to force the refresh and make the document available for search and count.

> curl [http://10.0.0.1:9200/clef2018/\_refresh](http://10.0.0.1:9200/clef2018/_refresh)

> **[Refresh | Elasticsearch Guide \[7.0\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/7.0/indices-refresh.html)**

---

<div class="post-metadata">

**Author:** ![lemon\_soft](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lemon_soft/32/43072_2.png) [@lemon\_soft](https://discuss.elastic.co/u/lemon_soft)\
**Post date:** [April 18, 2019, 9:18am UTC](https://discuss.elastic.co/t/after-putting-index-setting-cannot-add-document/177311/6 "2019-04-18T09:18:57Z")

</div>

Hi,  
Sorry, refresh command didn't succeed. Still count is zero. I deleted index and created again, but nothing worked ☹

---

<div class="post-metadata">

**Author:** ![gabriel\_tessier](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gabriel_tessier/32/27911_2.png) [@gabriel\_tessier](https://discuss.elastic.co/u/gabriel_tessier)\
**Post date:** [April 18, 2019, 9:26am UTC](https://discuss.elastic.co/t/after-putting-index-setting-cannot-add-document/177311/7 "2019-04-18T09:26:50Z")

</div>

There's something strange in your test

> {"\_index":"clef2018","\_type":"\_doc","\_id":"1","\_version":9,"\_seq\_no":74,"\_primary\_term":2,"found":true,"\_source":{ "content": "Hello world"}}

Here you have \_version == 9 which mean that you update your doc with id 1, 9 times and \_seq\_no ==74 which mean that you also insert/delete/update 74 (-9 for the document 1) times other documents???

the command you write are really the one you run? if so there's something strange with the meta fields.

---

<div class="post-metadata">

**Author:** ![lemon\_soft](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lemon_soft/32/43072_2.png) [@lemon\_soft](https://discuss.elastic.co/u/lemon_soft)\
**Post date:** [April 18, 2019, 10:00am UTC](https://discuss.elastic.co/t/after-putting-index-setting-cannot-add-document/177311/8 "2019-04-18T10:00:09Z")

</div>

Yes. I ran it repeatedly. Here is fresh result after deleting index and creating again:

> {"\_index":"clef2018","\_type":"\_doc","\_id":"1","\_version":1,"\_seq\_no":0,"\_primary\_term":2,"found":true,"\_source":{ "content": "Hello world" }}

Should I upgrade 6.7 to 7.0?

---

<div class="post-metadata">

**Author:** ![gabriel\_tessier](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gabriel_tessier/32/27911_2.png) [@gabriel\_tessier](https://discuss.elastic.co/u/gabriel_tessier)\
**Post date:** [April 18, 2019, 10:31am UTC](https://discuss.elastic.co/t/after-putting-index-setting-cannot-add-document/177311/9 "2019-04-18T10:31:50Z")

</div>

I tried with your data there's a problem in your settings definition actually you wrote

,"mappings":{"docType": \<--- but you insert in \_doc which make confusion...

Here the command I run and I have result for count and search. I only removed the call for terrier\_stopwords as I don't have the file.

Can you confirm that it's work for you. I tested on a 6.5.x

```
PUT clef2018
{
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 0,
    "analysis": {
      "analyzer": {
        "my_english": {
          "tokenizer": "standard",
          "filter": [
            "lowercase",
            "porter_stem"
          ]
        }
      }
    },
    "similarity": {
      "bm25_content": {
        "type": "BM25",
        "b": 0.75,
        "k1": 1.2
      }
    }
  },
  "mappings": {
    "docType": {
      "_source": {
        "enabled": true
      },
      "properties": {
        "content": {
          "type": "text",
          "similarity": "bm25_content",
          "analyzer": "my_english"
        },
        "is_html": {
          "type": "boolean"
        }
      }
    }
  }
}

POST clef2018/docType/1
{ "content": "Hello world"}

GET /clef2018/docType/1

GET /clef2018/docType/_count

GET /clef2018/docType/_search
```

---

<div class="post-metadata">

**Author:** ![lemon\_soft](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lemon_soft/32/43072_2.png) [@lemon\_soft](https://discuss.elastic.co/u/lemon_soft)\
**Post date:** [April 18, 2019, 10:49am UTC](https://discuss.elastic.co/t/after-putting-index-setting-cannot-add-document/177311/10 "2019-04-18T10:49:46Z")

</div>

You are exactly right. The problem is in setting string. I checked the website which gives the settings and changed `docType`.

Thanks for all your efforts 😌 @gabriel_tessier

adding worked:

```
PUT _doc/1
{"content": "Hello world"}

```

searching worked:

> GET \_doc/\_search?pretty=true  
> { "took" : 0, "timed\_out" : false, "\_shards" : { "total" : 1, "successful" : 1, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : 1, "max\_score" : 1.0, "hits" : [{ "\_index" : "example", "\_type" : "\_doc", "\_id" : "1", "\_score" : 1.0, "\_source" : { "content" : "Hello world" } }] } }

---

<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:** [May 16, 2019, 10:49am UTC](https://discuss.elastic.co/t/after-putting-index-setting-cannot-add-document/177311/11 "2019-05-16T10:49:48Z")

</div>

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