Mysql to Elastic Search query convert


(Rabeet waqar) #1

Hello,

Please any one will help me out with converting mysql queries to elasticsearch.

I have this query :

SELECT DISTINCT (email) FROM my_table

Is it possible?
@polyfractal
Thanks


(Mark Walkom) #2

Try https://www.elastic.co/guide/en/elasticsearch/guide/current/cardinality.html


(Rabeet waqar) #3

I'm trying it using PHP api, but no success

My ES query :
$aFindCountries = array();
$aFindCountries['index'] = 'my_table';
$aFindCountries['type'] = 'data';
$aFindCountries['body'] = array(

'size' => 0,
'query' => array(
    'filtered' => array(
        'query' => array(
            'query_string' => array(
                'query' => '*',
                'analyze_wildcard' => true
            )

        )
    )
),
'aggs' => array(
    'Distinct' => array(
        'terms' => array(
            'field' => 'user_country',
            'size' => 155,
            'order' => 'desc'
        )
    )
),

);

I want to find the distinct country names from my_table;
Thanks


(system) #4