php - 相同查询的elasticsearch浏览器和php客户端的不同结果

标签 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);

如果图像似乎没有:
浏览器中的网址: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",

...

最佳答案

这样做的主要原因是因为两个查询不相等。

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

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

official doc:

The query string “mini-language” is used by the Query String Query and by the q query string parameter in the search API.

关于php - 相同查询的elasticsearch浏览器和php客户端的不同结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31513741/

相关文章:

elasticsearch - 如何在Elasticsearch中找到所有包含 “blah”的对象?

php - Tcpdf - 启用滚动

php - 如何将硬编码数组数据定义为 PHP 框架的一部分?

php - 如何添加 Auth 作为 Controller 依赖项以在 Laravel 4 中进行测试

elasticsearch - 自定义char_filter用于 Elasticsearch 中的模式

elasticsearch - 如何在elasticsearch中使用查询DSL找到最近/最近的数字

php - MySql - 根据匹配的 id 获取行

php - VSCode/Xdebug PHP 中没有显示变量

elasticsearch - 使用Logstash从SQL Server到Elasticsearch进行增量索引

elasticsearch - Elasticsearch-使用条件衰减函数搜索多个索引