Skip to content

Commit bfda26e

Browse files
authored
[DOCS] Add CBOR example to ingest attachment docs (#60919)
1 parent 00881d9 commit bfda26e

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

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

0 commit comments

Comments
 (0)