0

I am new to ElasticsSearch and was messing around with it today. I have a node running on my localhost and was creating/updating my cat index. As I was adding more documents into my cat indexes, I noticed that when I do a GET request to see all of the documents in Postman, the new cats I make are not being added. I started noticing the issue after I added my tenth cat. All code is below.

ElasticSearch Version: 6.4.0 Python Version: 3.7.4

  my_cat_mapping = {
      "mappings": {
        "_doc": { 
          "properties": { 
            "breed":    { "type": "text"  }, 
            "info" : {
                "cat" :  {"type" : "text"},
                "name" :      {"type" : "text"},
                "age" : {"type" : "integer"},
                "amount"  : {"type" : "integer"}
            },  
            "created"  :  {
              "type":   "date", 
              "format": "strict_date_optional_time||epoch_millis"
            }
          }
        }
      }
    }



cat_body = {
    "breed" : "Persian Cat",
        "info":{
            "cat":"Black Cat",
            "name": " willy",
            "age": 5,
            "amount": 1
        }

}



def document_add(index_name, doc_type, body, doc_id = None):
    """Funtion to add a document by providing index_name,
    document type, document contents as doc and document id."""
    resp = es.index(index=index_name, doc_type=doc_type, body=body, id=doc_id)
        print(resp)


document_add("cat", "cat_v1", cat_body, 100 )

1 Answer 1

2

Since the document id is passed as 100 it just updates the same cat document. I'm assuming its not changed on every run !?

You have to change the document id doc_id with every time to add new cat instead of updating existing ones.

...

cat_id = 100
cat_body = {
    "breed" : "Persian Cat",
        "info":{
            "cat":"Black Cat",
            "name": " willy",
            "age": 5,
            "amount": 1
        }
}

...

document_add("cat", "cat_v1", cat_body, cat_id )

With this you can change both cat_id and cat_body to get new cats.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.