Organizational Research By

Surprising Reserch Topic

Experts Most Trusted Topic


elasticsearc search with codeiniter with php


Searching

Let's see if we can retrieve the documents we just added via search.

Find all blog posts by Dilbert:

curl 'http://localhost:9200/blog/post/_search?q=user:dilbert&pretty=true'

This returns the following JSON result:

{
  "took" : 85,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 3,
    "max_score" : 1.0,
    "hits" : [ {
      "_index" : "blog",
      "_type" : "post",
      "_id" : "1",
      "_score" : 1.0, "_source" : 
{ 
    "user": "dilbert", 
    "postDate": "2011-12-15", 
    "body": "Search is hard. Search should be easy." ,
    "title": "On search"
}
    }, {
      "_index" : "blog",
      "_type" : "post",
      "_id" : "2",
      "_score" : 0.30685282, "_source" : 
{ 
    "user": "dilbert", 
    "postDate": "2011-12-12", 
    "body": "Distribution is hard. Distribution should be easy." ,
    "title": "On distributed search"
}
    }, {
      "_index" : "blog",
      "_type" : "post",
      "_id" : "3",
      "_score" : 0.30685282, "_source" : 
{ 
    "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"
}
    } ]
  }
 

Nice!

All posts which don't contain the term search:

curl 'http://localhost:9200/blog/post/_search?q=-title:search&pretty=true'

Retrieve the title of all posts which contain search and not distributed:

curl 'http://localhost:9200/blog/post/_search?q=+title:search%20-title:distributed&pretty=true&fields=title'

A range search on postDate:

curl -XGET 'http://localhost:9200/blog/_search?pretty=true' -d '
{ 
    "query" : { 
        "range" : { 
            "postDate" : { "from" : "2011-12-10", "to" : "2011-12-12" } 
        } 
    } 
}'

You'll learn more about the various URL query parameters in a separate tutorial.

The usual Lucene query syntax is available either through the JSON query language, or through the query parser.


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



Related Hot Questions



Government Jobs Opening


...