cURL function for multiple Filter PHP


(Howzit) #1

I am using ElasticSearch in the Codeigniter Framework.
My hosting Company do not allow Elasticsearch as service on my managed server.

I am new to Elastic search and am testing it using a remote server at facetflow.

I cannot install Elastic PHP for same reason above.
I had to resolve in using a CI Library found here: https://github.com/confact/elasticsearch-codeigniter-library

I can index, delete, update and do basic searching.

I am stuck where I should create a multiple term search.

Is there any indication on how I should then, with PHP be able to create a multiple term query like the following?

curl -XGET https://domain/type/_search -d '{ "query": { "filtered": { "query": { "query_string": { "query": "Car For Sale" } }, "filter": { "bool" : { "must" : [ {"term" : { "provid" : "5" } }, {"term" : { "areaid" : "16" } }, {"term" : { "catid" : "3" } } ] } } } } }'


(Clay Gorman) #2

I do something like

$searchParams['body']['query']['filtered']['filter']['bool']['must'][]['term']['provid'] = 5;
$searchParams['body']['query']['filtered']['filter']['bool']['must'][]['term']['areaid'] = 16;
$searchParams['body']['query']['filtered']['filter']['bool']['must'][]['term']['catid'] = 3;

I also recommend var_dump(json_encode($searchParams['body'], JSON_PRETTY_PRINT)); to debug your body and use sense plugin.

Also note filtered query is deprecated in 2.0 if thats what you are running


(system) #3