Querying Elasticsearch
Refer to the link http://dbversity.com/elasticsearch/ for the Elasticserach installation before proceding to below post.
[root@dbversitydotcom elasticsearch]# ps -ef | grep ela
root 1316 1 0 Nov24 ? 00:07:24 /usr/java/jdk1.7.0_71/bin/java -Xms256m -Xmx1g -Xss256k -Djava.awt.headless=true -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+HeapDumpOnOutOfMemoryError -XX:+DisableExplicitGC -Delasticsearch -Des.foreground=yes -Des.path.home=/data/3/elasticsearch -cp :/data/3/elasticsearch/lib/elasticsearch-1.4.0.jar:/data/3/elasticsearch/lib/*:/data/3/elasticsearch/lib/sigar/* org.elasticsearch.bootstrap.Elasticsearch
root 17648 3971 5 05:17 pts/3 00:00:24 /usr/java/jdk1.7.0_71/bin/java -Xms256m -Xmx1g -Xss256k -Djava.awt.headless=true -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+HeapDumpOnOutOfMemoryError -XX:+DisableExplicitGC -Delasticsearch -Des.foreground=yes -Des.path.home=/data/3/elasticsearch -cp :/data/3/elasticsearch/lib/elasticsearch-1.4.0.jar:/data/3/elasticsearch/lib/*:/data/3/elasticsearch/lib/sigar/* org.elasticsearch.bootstrap.Elasticsearch
root 19590 22296 23 05:24 pts/4 00:00:16 /usr/java/jdk1.7.0_71/bin/java -Xms256m -Xmx1g -Xss256k -Djava.awt.headless=true -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+HeapDumpOnOutOfMemoryError -XX:+DisableExplicitGC -Delasticsearch -Des.foreground=yes -Des.path.home=/data/3/elasticsearch -cp :/data/3/elasticsearch/lib/elasticsearch-1.4.0.jar:/data/3/elasticsearch/lib/*:/data/3/elasticsearch/lib/sigar/* org.elasticsearch.bootstrap.Elasticsearch
[root@dbversitydotcom elasticsearch]#
Inserting data to Elastic search
[root@dbversitydotcom 3]# curl -XPUT 10.40.87.37:9201/dbversity/comments/2 -d ‘
{
user :”dbversit”,
message : “www.dbversity.com is the place for all databases information”,
postDate : “20141125T14:00”
}’
{“_index”:”dbversity”,”_type”:”comments”,”_id”:”1″,”_version”:1,”created”:true}
[root@dbversitydotcom 3]#
[root@dbversitydotcom 3]#
[root@dbversitydotcom 3]# curl -XPUT 10.40.87.37:9201/dbversity/comments/2 -d ‘
> {
> user :”dbversit”,
> message : “www.dbversity.com is the place for all databases information”,
> postDate : “20141125T14:00”
> }’
{“_index”:”dbversity”,”_type”:”comments”,”_id”:”2″,”_version”:1,”created”:true}
[root@dbversitydotcom 3]#
[root@dbversitydotcom 3]#
[root@dbversitydotcom elasticsearch]# curl -XGET 10.40.87.37:9201/dbversity/comments/1
{“_index”:”dbversity”,”_type”:”comments”,”_id”:”1″,”_version”:1,”found”:true,”_source”:
{
user :”dbversit”,
message : “welcome to elastic search, hope you will like it”,
postDate : “20141125T12:00”
}}
[root@dbversitydotcom elasticsearch]#
[root@dbversitydotcom elasticsearch]# curl -XGET 10.40.87.37:9201/dbversity/comments/2
{“_index”:”dbversity”,”_type”:”comments”,”_id”:”2″,”_version”:1,”found”:true,”_source”:
{
user :”dbversit”,
message : “www.dbversity.com is the place for all databases information”,
postDate : “20141125T14:00”
}}
[root@dbversitydotcom elasticsearch]#
[root@dbversitydotcom elasticsearch]# curl -XGET 10.40.87.37:9202/dbversity/comments/_search
{“took”:12,”timed_out”:false,”_shards”:{“total”:5,”successful”:5,”failed”:0},”hits”:{“total”:2,”max_score”:1.0,”hits”:[{“_index”:”dbversity”,”_type”:”comments”,”_id”:”1″,”_score”:1.0,”_source”:
{
user :”dbversit”,
message : “welcome to elastic search, hope you will like it”,
postDate : “20141125T12:00”
}},{“_index”:”dbversity”,”_type”:”comments”,”_id”:”2″,”_score”:1.0,”_source”:
{
user :”dbversit”,
message : “www.dbversity.com is the place for all databases information”,
postDate : “20141125T14:00”
}}]}}
[root@dbversitydotcom elasticsearch]#
[root@dbversitydotcom elasticsearch]# curl -XGET 10.40.87.37:9202/dbversity/comments/_search?q=user:dbversit
{“took”:70,”timed_out”:false,”_shards”:{“total”:5,”successful”:5,”failed”:0},”hits”:{“total”:2,”max_score”:0.30685282,”hits”:[{“_index”:”dbversity”,”_type”:”comments”,”_id”:”1″,”_score”:0.30685282,”_source”:
{
user :”dbversit”,
message : “welcome to elastic search, hope you will like it”,
postDate : “20141125T12:00”
}},{“_index”:”dbversity”,”_type”:”comments”,”_id”:”2″,”_score”:0.30685282,”_source”:
{
user :”dbversit”,
message : “www.dbversity.com is the place for all databases information”,
postDate : “20141125T14:00”
}}]}}
[root@dbversitydotcom elasticsearch]#
[root@dbversitydotcom elasticsearch]# curl -XGET 10.40.87.37:9202/dbversity/comments/_search?q=message:search
{“took”:24,”timed_out”:false,”_shards”:{“total”:5,”successful”:5,”failed”:0},”hits”:{“total”:1,”max_score”:0.095891505,”hits”:[{“_index”:”dbversity”,”_type”:”comments”,”_id”:”1″,”_score”:0.095891505,”_source”:
{
user :”dbversit”,
message : “welcome to elastic search, hope you will like it”,
postDate : “20141125T12:00”
}}]}}
[root@dbversitydotcom elasticsearch]#
[root@dbversitydotcom elasticsearch]# curl -XGET 10.40.87.37:9202/dbversity/comments/_search?q=message:databases
{“took”:40,”timed_out”:false,”_shards”:{“total”:5,”successful”:5,”failed”:0},”hits”:{“total”:1,”max_score”:0.095891505,”hits”:[{“_index”:”dbversity”,”_type”:”comments”,”_id”:”2″,”_score”:0.095891505,”_source”:
{
user :”dbversit”,
message : “www.dbversity.com is the place for all databases information”,
postDate : “20141125T14:00”
}}]}}
[root@dbversitydotcom elasticsearch]#
[root@dbversitydotcom elasticsearch]#
Now, insert more data with count field as below to check range query.
[root@dbversitydotcom elasticsearch]# curl -XGET 10.40.87.37:9202/dbversity/comments/_search
{“took”:12,”timed_out”:false,”_shards”:{“total”:5,”successful”:5,”failed”:0},”hits”:{“total”:7,”max_score”:1.0,”hits”:[{“_index”:”dbversity”,”_type”:”comments”,”_id”:”4″,”_score”:1.0,”_source”:
{
user :”dbversit”,
message : “www.dbversity.com is the place for all databases information”,
postDate : “20141125T14:00”,
count : “280”
}},{“_index”:”dbversity”,”_type”:”comments”,”_id”:”5″,”_score”:1.0,”_source”:
{
user :”dbversit”,
message : “www.dbversity.com is the place for all databases information”,
postDate : “20141125T14:00”,
count : “290”
}},{“_index”:”dbversity”,”_type”:”comments”,”_id”:”1″,”_score”:1.0,”_source”:
{
user :”dbversit”,
message : “welcome to elastic search, hope you will like it”,
postDate : “20141125T12:00”
}},{“_index”:”dbversity”,”_type”:”comments”,”_id”:”6″,”_score”:1.0,”_source”:
{
user :”dbversit”,
message : “www.dbversity.com is the place for all databases information”,
postDate : “20141125T14:00”,
count : “310”
}},{“_index”:”dbversity”,”_type”:”comments”,”_id”:”2″,”_score”:1.0,”_source”:
{
user :”dbversit”,
message : “www.dbversity.com is the place for all databases information”,
postDate : “20141125T14:00”
}},{“_index”:”dbversity”,”_type”:”comments”,”_id”:”7″,”_score”:1.0,”_source”:
{
user :”dbversit”,
message : “www.dbversity.com is the place for all databases information”,
postDate : “20141125T14:00”,
count : “410”
}},{“_index”:”dbversity”,”_type”:”comments”,”_id”:”3″,”_score”:1.0,”_source”:
{
user :”dbversit”,
message : “www.dbversity.com is the place for all databases information”,
postDate : “20141125T13:00”
}}]}}
[root@dbversitydotcom elasticsearch]#
[root@dbversitydotcom elasticsearch]#
[root@dbversitydotcom elasticsearch]# curl -XGET 10.40.87.37:9202/dbversity/comments/6
{“_index”:”dbversity”,”_type”:”comments”,”_id”:”6″,”_version”:1,”found”:true,”_source”:
{
user :”dbversit”,
message : “www.dbversity.com is the place for all databases information”,
postDate : “20141125T14:00”,
count : “310”
}}
[root@dbversitydotcom elasticsearch]#
[root@dbversitydotcom elasticsearch]# curl -XGET 10.40.87.37:9202/dbversity/comments/_search -d ‘ { query : { range : { count : { from : “200” , to : “400” } } } } ‘
{“took”:17,”timed_out”:false,”_shards”:{“total”:5,”successful”:5,”failed”:0},”hits”:{“total”:3,”max_score”:1.0,”hits”:[{“_index”:”dbversity”,”_type”:”comments”,”_id”:”4″,”_score”:1.0,”_source”:
{
user :”dbversit”,
message : “www.dbversity.com is the place for all databases information”,
postDate : “20141125T14:00”,
count : “280”
}},{“_index”:”dbversity”,”_type”:”comments”,”_id”:”5″,”_score”:1.0,”_source”:
{
user :”dbversit”,
message : “www.dbversity.com is the place for all databases information”,
postDate : “20141125T14:00”,
count : “290”
}},{“_index”:”dbversity”,”_type”:”comments”,”_id”:”6″,”_score”:1.0,”_source”:
{
user :”dbversit”,
message : “www.dbversity.com is the place for all databases information”,
postDate : “20141125T14:00”,
count : “310”
}}]}}
[root@dbversitydotcom elasticsearch]#
[root@dbversitydotcom elasticsearch]#
[root@dbversitydotcom elasticsearch]#
[root@dbversitydotcom elasticsearch]#
[root@dbversitydotcom elasticsearch]# curl -XGET 10.40.87.37:9202/dbversity/comments/_search -d ‘ { query : { range : { count : { from : “300” , to : “400” } } } } ‘
{“took”:16,”timed_out”:false,”_shards”:{“total”:5,”successful”:5,”failed”:0},”hits”:{“total”:1,”max_score”:1.0,”hits”:[{“_index”:”dbversity”,”_type”:”comments”,”_id”:”6″,”_score”:1.0,”_source”:
{
user :”dbversit”,
message : “www.dbversity.com is the place for all databases information”,
postDate : “20141125T14:00”,
count : “310”
}}]}}[root@dbversitydotcom elasticsearch]#
http://dbversity.com/querying-elasticsearch/