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

ElasticSearch DSL query basics

Discussion in 'Enhanced Search Support' started by AndyB, Apr 12, 2013.

  1. AndyB

    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"
            }
        }
    }'
     
    
     
  2. AndyB

    AndyB Well-Known Member

    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;
    
    ?>
     
    
     

Share This Page