简体   繁体   English

如何使用InvokeHTTP从Apache Nifi执行ElasticSearch agg查询?

[英]How to execute ElasticSearch agg query from Apache Nifi using InvokeHTTP?

I want to execute the following query from Apache Nifi: 我想从Apache Nifi执行以下查询:

GET /myindex/_search
{
  "size": 0,
  "aggs": {
    "range": {
        "date_range": {
            "field": "Datetime",
            "ranges": [
                { 
                   "from": "2017-02-17T16:00:00Z||-1H/H",
                   "to": "2017-02-17T16:00:00Z||/H" 
                }
            ]
        }
    }
  }
}

I want to get the value of doc_count . 我想获取doc_count的值。

I tried to use InvokeHTTP and directly pasted the above-defined query into the field HTTP Method . 我尝试使用InvokeHTTP并将上面定义的查询直接粘贴到HTTP Method字段中。 I also set Remote URL to http://localhost:9200 . 我还将Remote URL设置为http://localhost:9200 I connected InvokeHTTP with PutFile in order to save a response on the disk. 我将InvokeHTTPPutFile连接InvokeHTTP ,以便将响应保存在磁盘上。 The relationship is Response . 关系是Response

When I run InvokeHTTP , it does not give me any error. 当我运行InvokeHTTP ,它不会给我任何错误。 However, it neither outputs any result (FlowFile for Response). 但是,它都不输出任何结果(用于响应的FlowFile)。 I am sure that the result is not an empty set, because I tested this query with curl . 我确定结果不是空集,因为我使用curl测试了此查询。

What is wrong with my approach? 我的方法有什么问题? Should I define HTTP Method in some different way? 我应该以其他方式定义HTTP Method吗?

For verbs like POST, PUT, and PATCH, you'd normally have the above JSON body as the content of a flow file and pass that to InvokeHttp, setting the correct verb and URL there. 对于POST,PUT和PATCH之类的动词,通常会将上述JSON正文作为流文件的内容,然后将其传递给InvokeHttp,并在其中设置正确的动词和URL。 However the InvokeHttp documentation states that the message body will not be sent for a GET verb. 但是,InvokeHttp文档指出不会为GET动词发送消息正文。

The good news is that the Elasticsearch REST API for the search endpoint supports both GET and POST. 好消息是,用于搜索端点的Elasticsearch REST API支持GET和POST。 From their latest doc: "Both HTTP GET and HTTP POST can be used to execute search with body. Since not all clients support GET with body, POST is allowed as well." 从他们最新的文档中可以得出:“ HTTP GET和HTTP POST均可用于通过主体执行搜索。由于并非所有客户端都支持通过主体进行GET,因此也允许进行POST。”

I would set the content of a flow file to the above JSON body (perhaps using GenerateFlowFile or ReplaceText), then use POST as the verb. 我将流文件的内容设置为上述JSON主体(也许使用GenerateFlowFile或ReplaceText),然后将POST用作动词。

There is a JsonQueryElasticsearch processor, which supports JSON elasticsearch queries. 有一个JsonQueryElasticsearch处理器,它支持JSON JsonQueryElasticsearch查询。

JsonQueryElasticsearch配置

Your query goes into the Query field. 您的查询进入“ Query字段。 The processor has hits and aggregations relations for you to process the result. 处理器具有hitsaggregations关系,以供您处理结果。

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

相关问题 Apache Nifi InvokeHttp超时问题 - Apache Nifi InvokeHttp Timeout Issue 如何使用Apache-nifi的InvokeHttp处理器附加文件发送http POST multipart / form-data请求? - How to send an http POST multipart/form-data request with a file attached using Apache-nifi's InvokeHttp processor? Apache Nifi:从 Java 应用程序执行/触发 Nifi 处理器 - Apache Nifi : Execute / Trigger Nifi Processor From Java Application 在 Nifi 中,如何让 HandleHttpResponse 返回 invokeHttp 处理器的响应? - In Nifi, how do I get the HandleHttpResponse to return the reponse of the invokeHttp processor? 如何通过HTTP从C#查询Elasticsearch? - How to query Elasticsearch from C# via HTTP? Apache Nifi:ListenHTTP vs HandleHTTPRequest - Apache Nifi : ListenHTTP vs HandleHTTPRequest 使用 InvokeHTTP 带有标头的 Ni-Fi Get 请求 - Ni-Fi Get request with headers using InvokeHTTP 具有DELETE方法的Worklight WL.Server.invokeHttp()不接受查询参数 - Worklight WL.Server.invokeHttp() with DELETE method doesn't accept query param 如何使用Apache HttpComponents从Java套接字获取HTTPRequest - How to get an HTTPRequest from a Java Socket using Apache HttpComponents 如何使用Perl从Apache Solr中的响应获取numFound值 - How to get numFound value from response in Apache Solr using Perl
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM