jsonelasticsearchkibanasense

Elasticsearch - Sense - Indexing JSON files?


I'm trying to load some JSON files to my local ES instance via Sense, but I can't seem to figure the code out. I know ES has the Bulk API and the Index API, but I can't seem to bring the code together. How can I upload/index JSON files to my local ES instance using Sense? Thank you!


Solution

  • Yes, ES has a bulk api to upload JSON files to the ES cluster. I don't think that API is exposed in low level languages as in case of Sense it is Javascript in the browser. High level clients are available in Java or C# which expose more control over the ES cluster. I don't think chrome browser will support execution of this command.

    To upload a JSON file to elastic using the bulk api.

    1) This command uploads JSON documents from a JSON file.

    curl -s -XPOST localhost:9200/_bulk --data-binary @path_to_file;
    

    2)The JSON file should be formatted as follows:

    { "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" } }
    { "field1" : "value1" }
    { "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" } }
    { "field1" : "value3" }
    { "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" } }
    { "doc" : {"field2" : "value2"} }
    

    Where JSON object doc represents each JSON object data and the corresponding index JSON object represent metadata for that particular JSON doc like document id, type in index,index name.

    link to bulk upload

    Also you can refer my previous answer