elasticsearchelasticsearch-ruby

How to create ingest pipeline in elasticsearch using elasticsearch-ruby gem


I am struggling, How to create ingest attachment pipeline using elasticsearch-ruby gem?

For this call -

PUT _ingest/pipeline/attachment
{
  "description" : "Extract attachment information",
  "processors" : [
    {
      "attachment" : {
        "field" : "data"
      }
    }
  ]
}

Here is the exception which I am getting -

2.2.5 :008 > client.ingest.put_pipeline({id: 'attachment', body: {description: "Extract attachment information", processors: { attachment: { field: 'document_content', indexed_chars: '-1', indexed_chars_field: "max_size"}}}})
2018-04-27 08:22:07 +0530: PUT http://localhost:9200/_ingest/pipeline/attachment [status:400, request:0.108s, query:N/A]
2018-04-27 08:22:07 +0530: > {"description":"Extract attachment information","processors":{"attachment":{"field":"document_content","indexed_chars":"-1","indexed_chars_field":"max_size"}}}
2018-04-27 08:22:07 +0530: < {"error":{"root_cause":[{"type":"parse_exception","reason":"[processors] property isn't a list, but of type [java.util.HashMap]","header":{"property_name":"processors"}}],"type":"parse_exception","reason":"[processors] property isn't a list, but of type [java.util.HashMap]","header":{"property_name":"processors"}},"status":400}
2018-04-27 08:22:07 +0530: [400] {"error":{"root_cause":[{"type":"parse_exception","reason":"[processors] property isn't a list, but of type [java.util.HashMap]","header":{"property_name":"processors"}}],"type":"parse_exception","reason":"[processors] property isn't a list, but of type [java.util.HashMap]","header":{"property_name":"processors"}},"status":400}
Elasticsearch::Transport::Transport::Errors::BadRequest: [400] {"error":{"root_cause":[{"type":"parse_exception","reason":"[processors] property isn't a list, but of type [java.util.HashMap]","header":{"property_name":"processors"}}],"type":"parse_exception","reason":"[processors] property isn't a list, but of type [java.util.HashMap]","header":{"property_name":"processors"}},"status":400}

Solution

  • The error states

    [processors] property isn't a list, but of type [java.util.HashMap]

    In your REST call you had it correct, in that processors was an array, but in your ruby call you made it a hash.

    So the correct way to do it is like this:

     client.ingest.put_pipeline :id => 'attachment', :body => {description: "Extract attachment information", processors: [{ attachment: { field: 'document_content', indexed_chars: '-1', indexed_chars_field: "max_size"}}]}