Pages

Monday, January 21, 2013

Posting data to elasticsearch

Source: http://www.elasticsearchtutorial.com/elasticsearch-in-5-minutes.html

When the elasticsearch is working you would need to index data to the instance and you will do the same by the following steps.

We're now going to index some data to our ElasticSearch instance. We'll use the example of a blog engine, which has some posts and comments.
curl -XPUT 'http://localhost:9200/blog/user/dilbert' -d '{ "name" : "Dilbert Brown" }'

curl -XPUT 'http://localhost:9200/blog/post/1' -d '
{
    "user": "dilbert",
    "postDate": "2011-12-15",
    "body": "Search is hard. Search should be easy." ,
    "title": "On search"
}'


curl -XPUT 'http://localhost:9200/blog/post/2' -d '
{
    "user": "dilbert",
    "postDate": "2011-12-12",
    "body": "Distribution is hard. Distribution should be easy." ,
    "title": "On distributed search"
}'


curl -XPUT 'http://localhost:9200/blog/post/3' -d '
{
    "user": "dilbert",
    "postDate": "2011-12-10",
    "body": "Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat" ,
    "title": "Lorem ipsum"
}'
To each of these requests, you should have received a response that verifies that the operation was successful, for example:
{"ok":true,"_index":"blog","_type":"post","_id":"1","_version":1}

No comments:

Post a Comment