Search code examples
elasticsearchindexingapache-nifielastic-stack

http invoke method for Elasticsearch


I have to convert this to an http invoke method to use in Nifi to index data into elasticsearch. any help is appreciated.

my elastcisearch url: http://localhost:9200/elastcsearch

POST /doc1/_update_by_query

{
  "query": {
    "term": {
      "state_num": 4
    }
  },
  "script": {
    "inline": "ctx.\_source.documents.add(params.text)",
    "params": {
      "text": {
        "number": "1",
        "docs_content": "this text goes here"
      }
    }
  }
}

any help is appreciated.


Solution

  • You can try the following method

    1. Create an Invoke HTTP processor in NiFi.

    2. Set the HTTP Method property to POST.

    3. Set the Remote URL property to http://localhost:9200/doc1/_update_by_query.

    4. Set the Content-Type property to application/json.

    5. In the body of the request, include the JSON payload of the original request:

    {
      "query": {
        "term": {
          "state_num": 4
        }
      },
      "script": {
        "inline": "ctx._source.documents.add(params.text)",
        "params": {
          "text": {
            "number": "1",
            "docs_content": "this text goes here"
          }
        }
      }
    }
    
    1. Run the NiFi flow, and the data should be indexed into Elasticsearch.