A simple AND query with Elasticsearch

后端 未结 3 2042
执笔经年
执笔经年 2021-02-07 06:17

I am trying to do a simple query for two specified fields, and the manual and google is proving to be of little help. Example below should make it pretty clear what I want to do

3条回答
  •  失恋的感觉
    2021-02-07 06:39

    If composing the json with PHP, these 2 examples worked for me.

    $activeFilters is just a comma separated string like: 'attractions, limpopo'

    $articles = Article::searchByQuery(array(
            'match' => array(
                'cf_categories' => array(
                    'query' => $activeFilters,
                    'operator' =>'and'
                )
            )
        ));
    
        // The below code is also working 100%
        // Using Query String https://www.elastic.co/guide/en/elasticsearch/reference/1.4/query-dsl-query-filter.html
        // https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html
        /* $articles = Article::searchByQuery(array(
            'query_string' => array(
                'query' => 'cf_categories:attractions AND cf_categories:limpopo'
            )
        )); */
    

提交回复
热议问题