Hi check this Hope it will help you
$query = new Elastica_Query_Builder('{
"query": {
"bool": {
"must": {
"query_string": {
"query":"chicken",
"default_field": "_all"
}
},
"must_not": {
"query_string": {
"query":"Potatoes",
"default_field": "_all"
}
}
}
},
"facets": {
"active": {
"terms": {
"field": "active"
}
}
},
"sort":{
"id": {
"order": "desc"
}
},
"from": "0",
"size": "25"
}');
// Create a raw query since the query above can't be passed
directly to the search method used below
$query = new Elastica_Query($query->toArray());
// Create the search object and inject the client
$search = new Elastica_Search(new Elastica_Client());
// Configure and execute the search
$resultSet = $search->addIndex('foods')
->addType('food')
->search($query);
debug($resultSet);
On Tuesday, October 9, 2012 3:15:51 PM UTC+5, shannu wrote:
Hey Ivan ,
sorry to bother u again.
I am able to perform single keyword search, but unable to achieve the
multiple keyword search:
Single Keyword Search(works fine):
curl -XGET 'http://localhost/index/type/_search?pretty=true' -d '{"query"
: {"text":{"_all":"Shannu"}}}'
or
curl -XGET 'http://localhost/index/type/_search?pretty=true' -d '{"query"
: {"match":{"_all":"Shannu"}}}'
the above query bring back the correct results
Mutiple Keyword Search:
curl -XGET 'http://localhost/index/type/_search?pretty=true' -d '{"query"
: {"match":{"_all":["Shannu","Ivan","Something"]}}}' - this query executes
with out error but not the expected results
Result: {
"took" : 6,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 0,
"max_score" : null,
"hits" :
}
}
but I am expecting the items or docs which has those keywords I
mentioned..Am I missing something here in the query ?
or is there other way for multiple text search ???
Many thnx in Advance
Cheers,
Shannu.
On Monday, October 8, 2012 9:50:05 PM UTC+1, Ivan Brusic wrote:
The page I linked to already has an example. Here is another example with
your query, except with an added boolean query with a trivial text query.
{
"query": {
"bool": {
"must": {
"range": {
"Date": {
"from": "2012-10-03T09:00:00",
"to": "2012-10-03T14:00:00"
}
}
},
"must": {
"text": {
"_all": "elastic"
}
}
}
},
"filter": {
"term": {
"ID": "123"
}
},
"sort": {
"Timestamp": {
"order": "desc"
}
}
}
On Mon, Oct 8, 2012 at 9:23 AM, shannu shanmukh...@gmail.com wrote:
Hey Ivan ,
thanks a lot for the reply.
I am a newbie and struggling to work out this bit.
Do u mind sending me a sample query for single & multiple text search
and boolean query to combine range query and the text please.
That will be very helpful.
Regards,
Shannu.
On Monday, October 8, 2012 5:05:49 PM UTC+1, Ivan Brusic wrote:
Hi Shannu,
If I understand you correctly, you simply want to add more queries to
the existing range query? You can combine queries together using a boolean
query: http://www.**Elasticsearch Platform — Find real-time answers at scale | Elastic
**query.htmlhttp://www.elasticsearch.org/guide/reference/query-dsl/bool-query.html
The range query would be one clause and your text search would be
another clause that are "joined" together using a boolean query.
If you choose to use a filter instead, there is a boolean filter.
Cheers,
Ivan
On Mon, Oct 8, 2012 at 8:55 AM, shannu shanmukh...@gmail.com wrote:
Hello All,
I am trying to create a query to filter based on the date range
provided, search for specific ID and also with some "search text or some
search keywords"
I am able to fetch the records with the date range and ID provided,
but unable to search for any text within these records:
curl -XGET 'http://local:9200/Index/Type/**_search?pretty=truehttp://local:9200/Index/Type/_search?pretty=true'
-d '{ "query" : {"range" : {"Date" : { "from" : "2012-10-03T09:00:00", "to"
: "2012-10-03T14:00:00" }}},"filter" : {"term" : { "ID" : "123" }}, "sort":
{"Timestamp":{"order":"desc"}}**}'
The above query is working fine , but how do I add TEXT search to the
above query so that I can query based on smoe sample keywords and date
range and look for specific ID .
For example if I wanted to search for "Elastic" , "MyName" and
"Someother keyword"(wanted to perform single and mulitple keyword search)
in the "_source" field with in the documents.
Many Thanks in Advance
Regards,
Shannu.
--
--
--