Skip to content

Fix: bug on ES writing with fn options #167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Changed

### Fixed
* Fix bug on Elasticsearch write when using id, type & index functions.


## [0.7.27] - 2025-02-20
Expand Down
22 changes: 10 additions & 12 deletions src/clj/datasplash/es.clj
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ Examples:
([hosts index type p]
(read-es hosts index type {} p)))

(defn- ->ExtractKeyfn ^ExtractKeyFn
[doc-key-fn]
(ExtractKeyFn. (comp doc-key-fn (charred/parse-json-fn))))

(def ^:no-doc write-es-schema
(merge
es-connection-schema
Expand All @@ -99,20 +103,14 @@ Examples:
:action (fn [^ElasticsearchIO$Write transform [^Long max-attempts ^Long max-duration-ms]]
(.withRetryConfiguration transform (retry-config max-attempts max-duration-ms)))}
:id-fn {:doctstr "Provide a function to extract the id from the document."
:action (fn [^ElasticsearchIO$Write transform key-fn]
(let [serializing-key-fn #(charred/read-json % :key-fn key-fn)
id-fn (ExtractKeyFn. serializing-key-fn)]
(.withIdFn transform id-fn)))}
:action (fn [^ElasticsearchIO$Write transform doc-key-fn]
(.withIdFn transform (->ExtractKeyfn doc-key-fn)))}
:index-fn {:doctstr "Provide a function to extract the target index from the document allowing for dynamic document routing."
:action (fn [^ElasticsearchIO$Write transform key-fn]
(let [serializing-key-fn #(charred/read-json % :key-fn key-fn)
index-fn (ExtractKeyFn. serializing-key-fn)]
(.withIndexFn transform index-fn)))}
:action (fn [^ElasticsearchIO$Write transform doc-key-fn]
(.withIndexFn transform (->ExtractKeyfn doc-key-fn)))}
:type-fn {:docstr "Provide a function to extract the target type from the document allowing for dynamic document routing."
:action (fn [^ElasticsearchIO$Write transform key-fn]
(let [serializing-key-fn #(charred/read-json % :key-fn key-fn)
type-fn (ExtractKeyFn. serializing-key-fn)]
(.withTypeFn transform type-fn)))}
:action (fn [^ElasticsearchIO$Write transform doc-key-fn]
(.withTypeFn transform (->ExtractKeyfn doc-key-fn)))}
:use-partial-update {:docstr "Provide an instruction to control whether partial updates or inserts (default) are issued to Elasticsearch."
:action (fn [^ElasticsearchIO$Write transform is-partial-update]
(.withUsePartialUpdate transform is-partial-update))}}))
Expand Down
Loading