Pre Exam Test Practice (SSC | Banking | IAS | GATE | State Level | CLAT | Railways | Insurance | Teaching Exams | NDA | Defence | IES |State Exam )

Organizational Research By

Surprising Reserch Topic

elasticsearch Indexing Data with codeiniter php


Indexing Data

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}
Let's verify that all operations were successful.

curl -XGET 'http://localhost:9200/blog/user/dilbert?pretty=true'
curl -XGET 'http://localhost:9200/blog/post/1?pretty=true'
curl -XGET 'http://localhost:9200/blog/post/2?pretty=true'
curl -XGET 'http://localhost:9200/blog/post/3?pretty=true'
Note that there are 2 main ways of adding data to ElasticSearch:

json over HTTP
Native client
We'll explore these in greater detail in a subsequent tutorial.


asked Apr 19, 2015 in Elasticsearch-php by rajesh
0 votes
25 views



Related Hot Questions



Government Jobs Opening


...