relasticsearchropensci

how to index data using index_create() in elastic package in R


This is my code in R to index iris data.

library(elastic)
iris<-datasets::iris

body <- list(data = list(iris))

index_create(index = 'iris',body = body)

but it gives the following error.

Error: 400 - Failed to parse content to map. 
Please explain how to give data in the body of the index_create();

Solution

  • elastic maintainer here. index_create is only for creating an index as the function name indicates. That is, create an index, not create an index and insert data into the index. From your example you probably want

    index_create(index = "iris")
    docs_bulk(iris, "iris")