You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am stuggling to figure out how can one deserialize a valid JSON hit string into a SearchHit? We are using JSON string -> SearchHit pattern a lot in our tests and classic elasticsearch library SearchHit allowed to do the following:
and then store it into elastic4s SearchHit(_source = sourceMap). This however produces a different JSON representation during serialization back via hit.sourceAsString. For example, the original JSON
This drastically increases the resulting string size: 214 lines -> ~3k. So, this doesn't look like the correct way to create SearchHit from strings. So, how does one deserialize a string into SearchHit?
The text was updated successfully, but these errors were encountered:
Apparently, a workaround is possible if you use .sourceAsMap instead of .sourceAsString and then convert it to a new json string on your end. So the question is why .sourceAsString adds all that additional type metadata? It will index significantly more data if not checked :(
tastyminerals
changed the title
JSON string to SearchHit deserialization?
SearchHit.sourceAsString adds superfluous type metadata
Feb 19, 2024
This has something to do with the Jackson that elastic4s uses. So, whenever SearchHit is instantiated manually and _source is set. The downstream .sourceAsString will generate a json with type elements. We avoid it now only by calling .sourceAsMap on the manually instantiated SearchHit, converting the result map into Json object and then back to String using circe.
I am stuggling to figure out how can one deserialize a valid JSON hit string into a
SearchHit
? We are using JSON string ->SearchHit
pattern a lot in our tests and classic elasticsearch librarySearchHit
allowed to do the following:The elastic4s
SearchHit
doesn't providesourceRef
. Hence, we parse (via circe) a JSON string into aMap[String, Any]
and then store it into elastic4s
SearchHit(_source = sourceMap)
. This however produces a different JSON representation during serialization back viahit.sourceAsString
. For example, the original JSONbecomes
This drastically increases the resulting string size: 214 lines -> ~3k. So, this doesn't look like the correct way to create
SearchHit
from strings. So, how does one deserialize a string intoSearchHit
?The text was updated successfully, but these errors were encountered: