• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

ElasticSearch DSL query basics

AndyB

Well-known member
#1
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"
        }
    }
}'
 

AndyB

Well-known member
#2
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;

?>