Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how insert data to Elasticsearch without id

I insert data to Elasticsearch with id 123

localhost:9200/index/type/123

but I do not know what will next id inserted

how insert data to Elasticsearch without id in localhost:9200/index/type?

like image 556
proger2014 Avatar asked Jul 15 '14 10:07

proger2014


1 Answers

If our data doesn’t have a natural ID, we can let Elasticsearch autogenerate one for us. The structure of the request changes: instead of using the PUT verb ("store this document at this URL"), we use the POST verb ("store this document under this URL"). The URL now contains just the _index and the _type:

curl -X POST "localhost:9200/website/blog/" -H 'Content-Type: application/json' -d'
{
  "title": "My second blog entry",
  "text":  "Still trying this out...",
  "date":  "2014/01/01"
}
'

The response is similar to what we saw before, except that the _id field has been generated for us:

{
   "_index":    "website",
   "_type":     "blog",
   "_id":       "AVFgSgVHUP18jI2wRx0w",
   "_version":  1,
   "created":   true
}

Autogenerated IDs are 20 character long, URL-safe, Base64-encoded GUID strings. These GUIDs are generated from a modified FlakeID scheme which allows multiple nodes to be generating unique IDs in parallel with essentially zero chance of collision.

https://www.elastic.co/guide/en/elasticsearch/guide/current/index-doc.html

like image 121
Raj Hirani Avatar answered Sep 18 '22 20:09

Raj Hirani