Reputation:
I am new to Elasticearch, and I have been trying for 2 days to insert some data into Elasticearch. I found on Google that there are many pages to help to create an index (I am not clear about "index", does it mean "insert" in other terms?) Then many places give some curl command, and I really don't know where to execute these code lines to insert data. Example:
curl -XPOST "http://[localhost]:9200/indexname/typename/optionalUniqueId" -d '{ "field" : "value" }'
I am using Window 7 and I have installed Java and run elasticsearch successfully. Could anybody show me more details about how to insert data into Elasticearch
Many thanks
Upvotes: 96
Views: 334518
Reputation: 2286
If you are using Kibana with Elasticsearch then you can use below REST request to create and put in the index.
http://localhost:9200/company
PUT 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"
}
}
}
}
}
POST http://localhost:9200/company/employee/2/_create
{
"name": "Hemani",
"age" : 23,
"experienceInYears" : 2
}
Upvotes: 25
Reputation: 921
if someone wants just to copy-paste the command to send data to elastic search with username and password using curl:
make sure you change the command:
here is the command:
curl -u YOUR_USERNAME:YOUR_PASSWORD -H "Content-Type: application/json" -XPOST "https://YOUR-ELASTICSEARCH-URL.com/adam/test" -d '{ "hello" : "world"}'
that's it.
Please note that:
the path of the command size is 2 (adam/test
) - then your can post to elastic search.
change the message to whatever you want e.g. '{ "data" : "good"}'
you don't have to use username and password - just remove this from the command:
-u YOUR_USERNAME:YOUR_PASSWORD
if you want to see data in kibana, don't forget to add index in kibana. (just in the UI menu - search for index pattern and add star *
)
a successful message looks something like this:
{"_index":"hello","_type":"world","_id":"QyBtfXsB-dsakdew29","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":0,"_primary_term":1}%
Upvotes: 1
Reputation: 952
To test and try curl requests from Windows, you can make use of Postman client Chrome extension. It is very simple to use and quite powerful.
Or as suggested you can install the cURL util.
A sample curl request is as follows.
curl -X POST -H "Content-Type: application/json" -H "Cache-Control: no-cache" -d '{
"user" : "Arun Thundyill Saseendran",
"post_date" : "2009-03-23T12:30:00",
"message" : "trying out Elasticsearch"
}' "http://10.103.102.56:9200/sampleindex/sampletype/"
I am also getting started with and exploring ES in vast. So please let me know if you have any other doubts.
EDIT: Updated the index name and type name to be fully lowercase to avoid errors and follow convention.
Upvotes: 10
Reputation: 39385
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\"}"
Upvotes: 104
Reputation: 619
I started off using curl
, but since have migrated to use kibana
. Here is some more information on the ELK stack from elastic.co (E elastic search, K kibana): https://www.elastic.co/elk-stack
With kibana your POST
requests are a bit more simple:
POST /<INDEX_NAME>/<TYPE_NAME>
{
"field": "value",
"id": 1,
"account_id": 213,
"name": "kimchy"
}
Upvotes: 4
Reputation: 8410
To avoid using curl or Chrome plugins you can just use the the built in windows Powershell. From the Powershell command window run
Invoke-WebRequest -UseBasicParsing "http://127.0.0.1:9200/sampleindex/sampleType/" -
Method POST -ContentType "application/json" -Body '{
"user" : "Test",
"post_date" : "2017/11/13 11:07:00",
"message" : "trying out Elasticsearch"
}'
Note the Index name MUST be in lowercase.
Upvotes: 1
Reputation: 19
Simple fundamentals, Elastic community has exposed indexing, searching, deleting operation as rest web service. You can interact elastic using curl or sense(chrome plugin) or any rest client like postman.
If you are just testing few commands, I would recommend can use of sense chrome plugin which has simple UI and pretty mature plugin now.
Upvotes: -7
Reputation: 5747
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..
Upvotes: 17