How to insert data into elasticsearch How to insert data into elasticsearch elasticsearch elasticsearch

How to insert data into elasticsearch


You have to install the curl binary in your PC first. You can download it from here.

After that unzip it into a folder. Lets say C:\curl. In that folder you'll find curl.exe file with several .dll files.

Now open a command prompt by typing cmd from the start menu. And type cd c:\curl on there and it will take you to the curl folder. Now execute the curl command that you have.

One thing, windows doesn't support single quote around around the fields. So you have to use double quotes. For example I have converted your curl command like appropriate one.

curl -H "Content-Type: application/json" -XPOST "http://localhost:9200/indexname/typename/optionalUniqueId" -d "{ \"field\" : \"value\"}"


Let me explain clearly.. If you are familiar With rdbms.. Index is database.. And index type is table.. It mean index is collection of index types., like collection of tables as database (DB).

in NOSQL.. Index is database and index type is collections. Group of collection as database..

To execute those queries... U need to install CURL for Windows.

Curl is nothing but a command line rest tool.. If you want a graphical tool.. Try

Sense plugin for chrome...

Hope it helps..


If you are using KIBANA with elasticsearch then you can use below RESt request to create and put in the index.

CREATING INDEX:

http://localhost:9200/companyPUT company{  "settings": {    "index": {      "number_of_shards": 1,      "number_of_replicas": 1    },    "analysis": {      "analyzer": {        "analyzer-name": {          "type": "custom",          "tokenizer": "keyword",          "filter": "lowercase"        }      }    }  },  "mappings": {    "employee": {      "properties": {        "age": {          "type": "long"        },        "experience": {          "type": "long"        },        "name": {          "type": "text",          "analyzer": "analyzer-name"        }      }    }  }}

CREATING DOCUMENT:

POST http://localhost:9200/company/employee/2/_create{"name": "Hemani","age" : 23,"experienceInYears" : 2}