Elasticsearch查询从cURL和Kibana提供不同的结果

时间:2018-07-31 07:06:35

标签: elasticsearch kibana sense

我是Elasticsearch和kibana的新手,并且正在尝试将Elasticsearch与PHP连接以生成一些报告。

我正在尝试运行一个查询,该查询在kibana意义上运行得很好,但是每当我对它进行查询时,都会令人惊讶地给出不同的结果。

GET /_search
{
  "query": {
    "filtered": {
      "query": {
        "query_string": {
          "query": "*",
          "analyze_wildcard": true
        }
      },
      "filter": {
        "bool": {
          "must": [
            {
              "query": {
                "query_string": {
                  "analyze_wildcard": true,
                  "query": "*"
                }
              }
            },
            {
              "range": {
                "start_time": {
                  "gte": 1532889000000,
                  "lte": 1532975399999,
                  "format": "epoch_millis"
                }
              }
            }
          ],
          "must_not": []
        }
      }
    }
  },
  "size": 0,
  "aggs": {
    "2": {
      "terms": {
        "field": "layers",
        "size": 50,
        "order": {
          "_count": "desc"
        }
      }
    }
  }
}

当我查询此查询时,它返回文档而不是合计结果。

我要去哪里错了? TIA

编辑:我正在研究Elasticsearch 2.3

我正在运行以检索结果的PHP代码:

$jarray=array (
    'query' =>
        array (
            'filtered' =>
                array (
                    'query' =>
                        array (
                            'query_string' =>
                                array (
                                    'query' => '*',
                                    'analyze_wildcard' => true,
                                ),
                        ),
                    'filter' =>
                        array (
                            'bool' =>
                                array (
                                    'must' =>
                                        array (
                                            0 =>
                                                array (
                                                    'query' =>
                                                        array (
                                                            'query_string' =>
                                                                array (
                                                                    'analyze_wildcard' => true,
                                                                    'query' => '*',
                                                                ),
                                                        ),
                                                ),
                                            1 =>
                                                array (
                                                    'range' =>
                                                        array (
                                                            'start_time' =>
                                                                array (
                                                                    'gte' => 1532889000000,
                                                                    'lte' => 1532975399999,
                                                                    'format' => 'epoch_millis',
                                                                ),
                                                        ),
                                                ),
                                        ),
                                    'must_not' =>
                                        array (
                                        ),
                                ),
                        ),
                ),
        ),
    'size' => 0,
    'aggs' =>
        array (
            2 =>
                array (
                    'terms' =>
                        array (
                            'field' => 'layer_count',
                            'size' => 50,
                            'order' =>
                                array (
                                    '_count' => 'desc',
                                ),
                        ),
                ),
        ),
);



$jdata=json_encode($jarray);
$url = '10.10.113.97:9200/my_index/_search';
echo $url.'<br><br><br><br><br><br>';




$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_GETFIELDS, json_encode($jdata));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$return = curl_exec($ch) or die(curl_error());
curl_close($ch);
print_r(stripcslashes($return));

1 个答案:

答案 0 :(得分:1)

在您的cURL代码中,您需要更改用于聚合部分的字段:

df['Shipment ID'].replace(regex=r"(\d{8}).*",value="\\1")

此外,您需要像这样发送您的请求。我担心的是,您发送的GET没有任何请求正文,ES只会忽略您的查询并执行常规搜索。

'aggs' =>
    array (
        2 =>
            array (
                'terms' =>
                    array (
                        'field' => 'layers',         <--- change this line
                        'size' => 50,
                        'order' =>
                            array (
                                '_count' => 'desc',
                            ),
                    ),
            ),
    ),