Hi
I have be working for more than 3 days in this and tried many forums to fix this but still not possible.
Also I am new to Elasticsearch as this is our first project to implement.
For me Create New Index and Get the Index has been working fine. Now i want to get the search results with "group by" like in sql.
Below scripts are what i am using now
Step 1 :
I have Installed Elasticsearch 2.0 in Ubuntu 14.04. I able to create new Index using below code. Also i am using PHP to call ES
$hosts = array('our ip address:9200');
$client = \Elasticsearch\ClientBuilder::create()->setHosts($hosts)->build();
$index = "IndexName";
$params['index'] = $index;
$params['type'] = 'xyz';
$params['body']["id"] = "1";
$params['body']["title"] = "PHP Developer";
$params['body']["location"] = "United States";
$client->index($params);
once the above code runs Index successfully created.
Step 2 :
Able to look into the created Index using below link
`http://our ip address:9200/IndexName/_search?q=PHP&pretty
{
"took" : 30,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 3,
"max_score" : 0.8968174,
"hits" : [ {
"_index" : "IndexName",
"_type" : "xyz",
"_id" : "1545680",
"_score" : 0.8968174,
"_source":{"id":"1545680","title":"PHP Developer","location":"United States"}
}, {
"_index" : "IndexName",
"_type" : "xyz",
"_id" : "1539771",
"_score" : 0.753807,
"_source":{"id":"1539771","title":"PHP Team Lead","location":"United States"}
}, {
"_index" : "IndexName",
"_type" : "xyz",
"_id" : "1539772",
"_score" : 0.253807,
"_source":{"id":"1539772","title":"PHP Lead","location":"India"}
}
....
Step 3: Now i want to add group by using below code
So i added the below mapping while creating new Index
$params['body']['mappings']['xyz']['properties']['location'] = array('type' => 'string','fields' => array("untouched" => array('type' => 'string','index' => 'not_analyzed')));
Step 4: I use below code for group by
$params['index'] = "IndexName";
$params['type'] = 'xyz';
$params['body']['query']['query_string'] = array("query" => "PHP","default_operator" => "AND" ,"fields" => array("title"));
$params['body']["aggs"] = array("location" => array("terms" => array("field" => "location.untouched")));
$response = $client->search($params);
Step 5: The response below i get
[aggregations] => Array
(
[location] => Array
(
[doc_count_error_upper_bound] => 0
[sum_other_doc_count] => 0
[buckets] => Array
(
)
)
)
Step 6: I removed .untounched from aggs
$params['body']["aggs"] = array("location" => array("terms" => array("field" => "location")));
I got the below response
[aggregations] => Array
(
[location] => Array
(
[doc_count_error_upper_bound] => 0
[sum_other_doc_count] => 0
[buckets] => Array
(
[0] => Array
(
[key] => united
[doc_count] => 2
)
[1] => Array
(
[key] => india
[doc_count] => 1
)
[2] => Array
(
[key] => states
[doc_count] => 2
)
)
)
)
From the step 6 output i got almost group by working but the problem is the key get separated count.
How to fix this issue?
is there any setting need to changed?
Help me to fix this issue
Thanks
Aravin