elasticsearch用于同一查询的浏览器和php客户端的不同结果

时间:2015-07-20 10:06:53

标签: php elasticsearch

我在下面运行此查询并检查结果返回144条记录,但是当我使用浏览器运行查询时它什么都不返回。我知道结果必须是相同的,无论如何这个api转换查询,但结果是不同的,不能理解原因

$elasticSearch = new Elasticsearch\Client(['hosts' => ['localhost:9200']]);
        $params = array();
        $json = '{
                    "query" : {
                        "match" : {
                            "logdata" : "_client_"
                        }
                    }
                    }';
        $params['body'] = $json;
        $params['index'] = 'accesslog_index';
        $params['size'] = 400;
        $query = $elasticSearch->search($params);

enter image description here

如果图片看起来不像: 浏览器中的网址:http://localhost:9200/accesslog_index/_search?pretty=true&q=logdata _client _ & size = 100 结果:

{
  "took" : 3,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 72,
    "max_score" : 1.0,
    "hits" : [ {
      "_index" : "accesslog_index",
      "_type" : "acceslogs_june",
      "_id" : "AU6R267Wy2aRfwCng6-y",

...

1 个答案:

答案 0 :(得分:1)

主要原因是两个查询不相等。

在查询DSL中,http://localhost:9200/accesslog_index/_search?q=logdata:*_client_*的等效查询不是match查询,而是query_string查询,如下所示:

{
    "query": {
        "query_string" : {
            "default_field" : "logdata",
            "query" : "*_client_*"
        }
    }
}

来自official doc

  

Query String Query使用查询字符串“mini-language”   通过搜索API中的q查询字符串参数。