简体   繁体   English

无法在Elasticsearch上请求数据

[英]Can't request data on elasticsearch

I am develloping graphs for connection logs of a website. 我正在为网站的连接日志设计图表。 Logs are parsed by logstash and served via elasticsearch. 日志由logstash解析,并通过elasticsearch提供。

I've develloped some graphs, nothing outstanding nor hard, but working. 我已经设计了一些图形,没有什么出色也不困难的,但是可以工作。

Friday I started elasticsearch, and every script I wrote to get the data fail when I send the query. 星期五,我开始了弹性搜索,当我发送查询时,为获取数据而编写的每个脚本都失败了。

My first thought was that I somehow modified the query, so I printed it and send it to elasticsearch (with plugin head). 我的第一个想法是,我以某种方式修改了查询,因此我将其打印并发送到elasticsearch(带有插件头)。 The query was fine and I have result. 查询很好,我有结果。

I tried purging logs from logstash and elasticsearch, and restarting to feed them from known good data... Didn't fix anything. 我尝试从logstash和elasticsearch中清除日志,然后重新启动以从已知的良好数据中获取日志...没有解决任何问题。

Tried to see if the config has any error, used a backup of a working one, didn't work either. 试图查看配置是否有任何错误,使用了工作正常的备份,也没有工作。

As last hope, I tried to print PHP errors, and I do get an exception thrown from deep inside of elasticsearch: 最后的希望是,我尝试打印PHP错误,但确实从elasticsearch的深处抛出了一个异常:

Fatal error: Uncaught exception 'Guzzle\Http\Exception\ServerErrorResponseException' with message 'Server error response [status code] 500 [reason phrase] 

Internal Server Error [url] http://localhost:9200/empreinte_index/mobile/_search' in /home/empreinte/vendor/guzzle/guzzle/src/Guzzle/Http/Exception/BadResponseException.php:43 

Stack trace: 
#0 /home/empreinte/vendor/guzzle/guzzle/src/Guzzle/Http/Message/Request.php(145): Guzzle\Http\Exception\BadResponseException::factory(Object(Guzzle\Http\Message\EntityEnclosingRequest), Object(Guzzle\Http\Message\Response)) 

#1 [internal function]: Guzzle\Http\Message\Request::onRequestError(Object(Guzzle\Common\Event), 'request.error', Object(Symfony\Component\EventDispatcher\EventDispatcher)) 

#2 /home/empreinte/vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/EventDispatcher.php(164): call_user_func(Array, Object(Guzzle\Common\Event), 'request.error', Object(Symfony\Component\EventDispatcher\EventDispatcher)) 

#3 /home/empreinte/vendor/symfony/event-dispatcher/Symfony in /home/empreinte/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/GuzzleConnection.php on line 238 

So this seems to comfort the idea that my codes are fine, but I can't find what did I done wrong, nor where to search. 因此,这似乎使我的代码很好的想法感到安慰,但是我找不到我做错了什么,也找不到在哪里进行搜索。

Here is a minimal example of the script I use: 这是我使用的脚本的最小示例:

<?php
    echo "Days";
    require '/home/empreinte/vendor/autoload.php';
    $client = new Elasticsearch\Client();

    $Query['index'] = 'empreinte_index';
    $Query['type'] = 'web';

    echo ".";

    //Building the timeframe needed. For brevity, using hardcoded data.

    $timeframe = "{"from" : "1404165600", "to" : "1404252000" },{"from" : "1404252000", "to" : "1404338400" }";

    echo ".";

    $Query['body']='
    {
        "aggs" : 
        {
            "temps" : 
            {
                "range" : 
                {
                    "field" : "time",
                    "ranges" : ['.$timeframe.']
                },
                "aggs" : 
                { 
                    "new_users" : 
                    { 
                        "terms" : 
                        { 
                            "field" : "is_newuser" 
                        } 
                    }
                }
            }
        }   
    }';

    echo ".";

    $result = $client->search($Query);

    //Parse the data to get them in usable form for graphs

    echo "OK</br>";

?>

Which output "Days...", And the exception if PHP is set to display it. 哪个输出为“ Days ...”,如果将PHP设置为显示它,则为例外。

(If requested, I'll post the config file and some logs). (如果需要,我将发布配置文件和一些日志)。

How can I fix this? 我怎样才能解决这个问题? Where can I find a similar error from which I can find a fix? 在哪里可以找到可以修复的类似错误? What does mean the error? 错误是什么意思?

If you check the response it looks like a request problem: 'request.error' 如果您检查响应,则它看起来像是一个请求问题: “ request.error”

When you construct the timeframe you use double quotes to construct the string but also within the string, this can be a problem as well. 当您构造时间范围时,您可以使用双引号来构造字符串,但也可以在字符串中构造字符串,这也可能是一个问题。

I do not really think this is the problem, but try to loose the quotes around the longs representing time stamps. 我并不是真的认为这是问题所在,但请尝试在代表时间戳的多头报价中松开报价。

Finally try to print the query and try the query in a tool like sense from elasticsearch or the head plugin or the kopf plugin. 最后尝试打印查询,并使用诸如Elasticsearch或head插件或kopf插件之类的工具尝试查询。

Hope that helps 希望能有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM