Home > Back-end >  Grouping elastic seach put commands
Grouping elastic seach put commands

Time:12-11

Is there a way to group 3 commands below into 1 command?

PUT /vehicles/_doc/123
{
  "make" : "Honda civic", 
  "color" : "Blue", 
  "from": "Japan",
  "size": "Big",
  "HP" : 250, 
  "milage" : 24000, 
  "price": 19300.97
}

PUT /vehicles/_doc/456
{
  "make" : "honda civic", 
  "color" : "Blue", 
  "from": "Singapore",
  "size": "Big",
  "HP" : 250, 
  "milage" : 24000, 
  "price": 19300.97
}

PUT /vehicles/_doc/789
{
  "make" : "Toyota", 
  "color" : "Blue", 
  "from": "Japan",
  "size": "Big",
  "HP" : 250, 
  "milage" : 24000, 
  "price": 19300.97
}

CodePudding user response:

You can use _bulk API as @Amit said. Here is a sample also:

POST vehicles/_bulk
{"index": {"_id": "123"}}
{"make" : "Honda civic", "color" : "Blue", "from": "Japan",  "size": "Big",  "HP" : 250, "milage" : 24000, "price": 19300.97}
{"index": {"_id": "456"}}
{"make" : "honda civic", "color" : "Blue", "from": "Singapore","size": "Big","HP" : 250, "milage" : 24000, "price": 19300.97}
{"index": {"_id": "789"}}
{"make" : "Toyota", "color" : "Blue", "from": "Japan","size": "Big","HP" : 250, "milage" : 24000, "price": 19300.97}

CodePudding user response:

Definitely you can use the Elasticsearch bulk API for indexing multiple index request into one request.

You can also specify the id of them, as you are using your own ids(not the Elasticsearch generated one) for your documents.

  • Related