HC LW
HC LW

Reputation: 197

Elasticsearch - bulk post data

(ES amateur here) I am using the Elasticsearch Bulk API through Jenkins (Groovy) to post multiple documents at once to an index. However, the following request in groovy only reads the first row of data and ignores the 5 other lines below it.

httpRequest url: "https://elasticsearchindex.url/here",
            httpMode: 'POST',
            contentType: 'APPLICATION_JSON',
            requestBody: "{\"hostname\" : \"playground.test\",\"postDate\" : \"2021-11-22T20:23:00\",\"device_id\" : \"${osList[0][0]}\",\"rule_name\" : \"${osList[0][1]}\",\"policy_name\" : \"${policyName}${osList[0][2]}\",\"rule_id\": \"${osList[0][3]}\"}\
                          {\"hostname\" : \"playground.test\",\"postDate\" : \"2021-11-22T20:23:00\",\"device_id\" : \"${osList[1][0]}\",\"rule_name\" : \"${osList[1][1]}\",\"policy_name\" : \"${policyName}${osList[1][2]}\",\"rule_id\": \"${osList[1][3]}\"}\
                          {\"hostname\" : \"playground.test\",\"postDate\" : \"2021-11-22T20:23:00\",\"device_id\" : \"${osList[2][0]}\",\"rule_name\" : \"${osList[2][1]}\",\"policy_name\" : \"${policyName}${osList[2][2]}\",\"rule_id\": \"${osList[2][3]}\"}\
                          {\"hostname\" : \"playground.test\",\"postDate\" : \"2021-11-22T20:23:00\",\"device_id\" : \"${osList[3][0]}\",\"rule_name\" : \"${osList[3][1]}\",\"policy_name\" : \"${policyName}${osList[3][2]}\",\"rule_id\": \"${osList[3][3]}\"}\
                          {\"hostname\" : \"playground.test\",\"postDate\" : \"2021-11-22T20:23:00\",\"device_id\" : \"${osList[4][0]}\",\"rule_name\" : \"${osList[4][1]}\",\"policy_name\" : \"${policyName}${osList[4][2]}\",\"rule_id\": \"${osList[4][3]}\"}\
                          {\"hostname\" : \"playground.test\",\"postDate\" : \"2021-11-22T20:23:00\",\"device_id\" : \"${osList[5][0]}\",\"rule_name\" : \"${osList[5][1]}\",\"policy_name\" : \"${policyName}${osList[5][2]}\",\"rule_id\": \"${osList[5][3]}\"}"
                   

Not sure if the API here is built for what I'm trying to do, or if I am writing it incorrectly. Thank you for the help!

Upvotes: 0

Views: 905

Answers (1)

Tomasz Dzierżanowski
Tomasz Dzierżanowski

Reputation: 74

You can post data like below using curl

curl -XPOST -u username:pass https://elasticsearchserver:9200/company/branch/_bulk -d'
    { "index": { "_id": "london" }}
    { "name": "London Westminster", "city": "London", "country": "UK" }
    { "index": { "_id": "liverpool" }}
    { "name": "Liverpool Central", "city": "Liverpool", "country": "UK" }
    { "index": { "_id": "paris" }}
    { "name": "Champs Élysées", "city": "Paris", "country": "France" }
'

That should give you output of creation.

enter image description here

Upvotes: 1

Related Questions