Образец вставки нескольких записей в один индекс, который может быть полезно для тестирования запросов. Обратите внимание, что на каждую запись есть два json-объекта: 1) указание на индекс, тип и ID и 2) сам вставляемый объект.
Индекс, тип, идентификатор
{"index": { "_index": "persons", "_type": "item", "_id": "1" }}
Вставляемая запись
{"name" : "Kurt Cobain", "year" : 1967, "sex" : "male"}
Запрос на вставку из txt-файла persons.txt
содержащего в себе описание вставляемых данных в json-формате. Обратите внимание, что в конце файла обязательно должна быть быть пустая строка
curl -X POST -H 'Content-Type: application/json' http://111.222.33.444:9200/_bulk --data-binary @persons.txt
Скачать файл: persons.txt
Запрос полностью
curl -X POST -H 'Content-Type: application/json' http://111.222.33.444:9200/_bulk -d '
{"index": { "_index": "persons", "_type": "item", "_id": "1" }}
{"name" : "Kurt Cobain", "year" : 1967, "sex" : "male"}
{"index": { "_index": "persons", "_type": "item", "_id": "2" }}
{"name" : "Angela Merkel", "year" : 1954, "sex" : "female"}
{"index": { "_index": "persons", "_type": "item", "_id": "3" }}
{"name" : "Vladimir Putin", "year" : 1952, "sex" : "male"}
{"index": { "_index": "persons", "_type": "item", "_id": "4" }}
{"name" : "Ksenia Sobchak", "year" : 1981, "sex" : "female"}
{"index": { "_index": "persons", "_type": "item", "_id": "5" }}
{"name" : "Fedor Emelianenko", "year" : 1976, "sex" : "male"}
{"index": { "_index": "persons", "_type": "item", "_id": "6" }}
{"name" : "Alina Kabaeva", "year" : 1983, "sex" : "female"}
{"index": { "_index": "persons", "_type": "item", "_id": "7" }}
{"name" : "Vladimir Vysotskiy", "year" : 1938, "sex" : "male"}
{"index": { "_index": "persons", "_type": "item", "_id": "8" }}
{"name" : "Edyta Piecha", "year" : 1937, "sex" : "female"}
{"index": { "_index": "persons", "_type": "item", "_id": "9" }}
{"name" : "Sergey Lemeshev", "year" : 1902, "sex" : "male"}
{"index": { "_index": "persons", "_type": "item", "_id": "10" }}
{"name" : "Sophia Loren", "year" : 1934, "sex" : "female"}
'
Ответ сервера после вставки
{
"took": 435,
"errors": false,
"items": [{
"index": {
"_index": "persons",
"_type": "item",
"_id": "1",
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 0,
"_primary_term": 1,
"status": 201
}
}, {
"index": {
"_index": "persons",
"_type": "item",
"_id": "2",
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 1,
"_primary_term": 1,
"status": 201
}
}, {
"index": {
"_index": "persons",
"_type": "item",
"_id": "3",
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 2,
"_primary_term": 1,
"status": 201
}
}, {
"index": {
"_index": "persons",
"_type": "item",
"_id": "4",
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 3,
"_primary_term": 1,
"status": 201
}
}, {
"index": {
"_index": "persons",
"_type": "item",
"_id": "5",
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 4,
"_primary_term": 1,
"status": 201
}
}, {
"index": {
"_index": "persons",
"_type": "item",
"_id": "6",
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 5,
"_primary_term": 1,
"status": 201
}
}, {
"index": {
"_index": "persons",
"_type": "item",
"_id": "7",
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 6,
"_primary_term": 1,
"status": 201
}
}, {
"index": {
"_index": "persons",
"_type": "item",
"_id": "8",
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 7,
"_primary_term": 1,
"status": 201
}
}, {
"index": {
"_index": "persons",
"_type": "item",
"_id": "9",
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 8,
"_primary_term": 1,
"status": 201
}
}, {
"index": {
"_index": "persons",
"_type": "item",
"_id": "10",
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 9,
"_primary_term": 1,
"status": 201
}
}]
}