ElasticSearch DSL query basics

AndyB

Well-known member
Here's an example of a DSL query to retrieve the word 'test' from all messages.

Code:
curl -XGET 'http://localhost:9200/xenforo_database_name/_search?pretty=true' -d '{
    "query": {
        "match" : {
            "message" : "test"
        }
    }
}'
 
Here's how you would run the above in a php script.

Code:
<?php

$data_string = '{
"query": {
        "match" : {
            "message" : "test"
        }
    }
}';

$ch = curl_init('http://localhost:9200/xenforo_database_name/_search?pretty=true');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
'Content-Type: application/json',                                                                                
'Content-Length: ' . strlen($data_string))                                                                       
); 
 
curl_setopt($ch, CURLOPT_POSTFIELDS,   $data_string );
curl_setopt($ch, CURLOPT_CUSTOMREQUEST,  'GET');

$result = curl_exec($ch);

echo $result;

?>
 
Back
Top Bottom