summaryrefslogtreecommitdiff
path: root/plugins/ingest-attachment
diff options
context:
space:
mode:
authorDavid Pilato <david@pilato.fr>2016-08-10 18:27:09 +0200
committerDavid Pilato <david@pilato.fr>2016-08-10 18:31:16 +0200
commit905684fe73e8ef05f3f1088a7d6fd4c0fd76be9c (patch)
treea963551e711b0df0665bbab527d04992bcf8b78e /plugins/ingest-attachment
parent90dbce9682e53a99462b81d6ac593f60c8a2ac7b (diff)
Adds content-length as number
If you run Elasticsearch with the ingest-attachment plugin: ```sh gradle plugins:ingest-attachment:run ``` And then you use it on a document: ```js PUT _ingest/pipeline/attachment { "description" : "Extract attachment information", "processors" : [ { "attachment" : { "field" : "data" } } ] } PUT my_index/my_type/my_id?pipeline=attachment { "data": "e1xydGYxXGFuc2kNCkxvcmVtIGlwc3VtIGRvbG9yIHNpdCBhbWV0DQpccGFyIH0=" } GET my_index/my_type/my_id ``` You were getting this back: ```js # PUT _ingest/pipeline/attachment { "acknowledged": true } # PUT my_index/my_type/my_id?pipeline=attachment { "_index": "my_index", "_type": "my_type", "_id": "my_id", "_version": 2, "result": "updated", "_shards": { "total": 2, "successful": 1, "failed": 0 }, "created": false } # GET my_index/my_type/my_id { "_index": "my_index", "_type": "my_type", "_id": "my_id", "_version": 2, "found": true, "_source": { "data": "e1xydGYxXGFuc2kNCkxvcmVtIGlwc3VtIGRvbG9yIHNpdCBhbWV0DQpccGFyIH0=", "attachment": { "content_type": "application/rtf", "language": "ro", "content": "Lorem ipsum dolor sit amet", "content_length": "28" } } } ``` With this commit you are now getting: ``` # GET my_index/my_type/my_id { "_index": "my_index", "_type": "my_type", "_id": "my_id", "_version": 2, "found": true, "_source": { "data": "e1xydGYxXGFuc2kNCkxvcmVtIGlwc3VtIGRvbG9yIHNpdCBhbWV0DQpccGFyIH0=", "attachment": { "content_type": "application/rtf", "language": "ro", "content": "Lorem ipsum dolor sit amet", "content_length": 28 } } } ``` Closes #19924
Diffstat (limited to 'plugins/ingest-attachment')
-rw-r--r--plugins/ingest-attachment/src/main/java/org/elasticsearch/ingest/attachment/AttachmentProcessor.java7
-rw-r--r--plugins/ingest-attachment/src/test/resources/rest-api-spec/test/ingest_attachment/20_attachment_processor.yaml4
-rw-r--r--plugins/ingest-attachment/src/test/resources/rest-api-spec/test/ingest_attachment/30_files_supported.yaml4
3 files changed, 10 insertions, 5 deletions
diff --git a/plugins/ingest-attachment/src/main/java/org/elasticsearch/ingest/attachment/AttachmentProcessor.java b/plugins/ingest-attachment/src/main/java/org/elasticsearch/ingest/attachment/AttachmentProcessor.java
index 4036fb0d68..0ba79ecc9f 100644
--- a/plugins/ingest-attachment/src/main/java/org/elasticsearch/ingest/attachment/AttachmentProcessor.java
+++ b/plugins/ingest-attachment/src/main/java/org/elasticsearch/ingest/attachment/AttachmentProcessor.java
@@ -119,7 +119,12 @@ public final class AttachmentProcessor extends AbstractProcessor {
if (properties.contains(Property.CONTENT_LENGTH)) {
String contentLength = metadata.get(Metadata.CONTENT_LENGTH);
- String length = Strings.hasLength(contentLength) ? contentLength : String.valueOf(parsedContent.length());
+ long length;
+ if (Strings.hasLength(contentLength)) {
+ length = Long.parseLong(contentLength);
+ } else {
+ length = parsedContent.length();
+ }
additionalFields.put(Property.CONTENT_LENGTH.toLowerCase(), length);
}
} catch (Exception e) {
diff --git a/plugins/ingest-attachment/src/test/resources/rest-api-spec/test/ingest_attachment/20_attachment_processor.yaml b/plugins/ingest-attachment/src/test/resources/rest-api-spec/test/ingest_attachment/20_attachment_processor.yaml
index 9c46610f10..cab1bfb591 100644
--- a/plugins/ingest-attachment/src/test/resources/rest-api-spec/test/ingest_attachment/20_attachment_processor.yaml
+++ b/plugins/ingest-attachment/src/test/resources/rest-api-spec/test/ingest_attachment/20_attachment_processor.yaml
@@ -33,7 +33,7 @@
- length: { _source.attachment: 4 }
- match: { _source.attachment.content: "This is an english text to test if the pipeline works" }
- match: { _source.attachment.language: "en" }
- - match: { _source.attachment.content_length: "54" }
+ - match: { _source.attachment.content_length: 54 }
- match: { _source.attachment.content_type: "text/plain; charset=ISO-8859-1" }
---
@@ -111,4 +111,4 @@
- length: { _source.attachment: 4 }
- match: { _source.attachment.content: "This is an english text to tes" }
- match: { _source.attachment.language: "en" }
- - match: { _source.attachment.content_length: "30" }
+ - match: { _source.attachment.content_length: 30 }
diff --git a/plugins/ingest-attachment/src/test/resources/rest-api-spec/test/ingest_attachment/30_files_supported.yaml b/plugins/ingest-attachment/src/test/resources/rest-api-spec/test/ingest_attachment/30_files_supported.yaml
index 3b9183e930..c8ab6f0ba9 100644
--- a/plugins/ingest-attachment/src/test/resources/rest-api-spec/test/ingest_attachment/30_files_supported.yaml
+++ b/plugins/ingest-attachment/src/test/resources/rest-api-spec/test/ingest_attachment/30_files_supported.yaml
@@ -34,7 +34,7 @@
- match: { _source.attachment.language: "et" }
- match: { _source.attachment.author: "David Pilato" }
- match: { _source.attachment.date: "2016-03-10T08:25:00Z" }
- - match: { _source.attachment.content_length: "19" }
+ - match: { _source.attachment.content_length: 19 }
- match: { _source.attachment.content_type: "application/msword" }
@@ -74,6 +74,6 @@
- match: { _source.attachment.language: "et" }
- match: { _source.attachment.author: "David Pilato" }
- match: { _source.attachment.date: "2016-03-10T08:24:00Z" }
- - match: { _source.attachment.content_length: "19" }
+ - match: { _source.attachment.content_length: 19 }
- match: { _source.attachment.content_type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document" }