Skip to content

Commit 069ad78

Browse files
authored
[DOCS] Add CBOR example to ingest attachment docs (#60919) (#60965)
1 parent 7a8f860 commit 069ad78

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

docs/plugins/ingest-attachment.asciidoc

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,53 @@ PUT _ingest/pipeline/attachment
9999
NOTE: Extracting contents from binary data is a resource intensive operation and
100100
consumes a lot of resources. It is highly recommended to run pipelines
101101
using this processor in a dedicated ingest node.
102+
103+
[[ingest-attachment-cbor]]
104+
==== Use the attachment processor with CBOR
105+
106+
To avoid encoding and decoding JSON to base64, you can instead pass CBOR data to
107+
the attachment processor. For example, the following request creates the
108+
`cbor-attachment` pipeline, which uses the attachment processor.
109+
110+
[source,console]
111+
----
112+
PUT _ingest/pipeline/cbor-attachment
113+
{
114+
"description" : "Extract attachment information",
115+
"processors" : [
116+
{
117+
"attachment" : {
118+
"field" : "data"
119+
}
120+
}
121+
]
122+
}
123+
----
124+
125+
The following Python script passes CBOR data to an HTTP indexing request that
126+
includes the `cbor-attachment` pipeline. The HTTP request headers use a
127+
a `content-type` of `application/cbor`.
128+
129+
NOTE: Not all {es} clients support custom HTTP request headers.
130+
131+
[source,python]
132+
----
133+
import cbor2
134+
import requests
135+
136+
file = 'my-file'
137+
headers = {'content-type': 'application/cbor'}
138+
139+
with open(file, 'rb') as f:
140+
doc = {
141+
'data': f.read()
142+
}
143+
requests.put(
144+
'http://localhost:9200/my-index-000001/_doc/my_id?pipeline=cbor-attachment',
145+
data=cbor2.dumps(doc),
146+
headers=headers
147+
)
148+
----
102149

103150
[[ingest-attachment-extracted-chars]]
104151
==== Limit the number of extracted chars

0 commit comments

Comments
 (0)