I am using Kuzzle in order to build a simple slack-like application. I have a simple collection with documents only containing other documents ids. I wanted to query a list of ids from this collection and got stuck with an empty hits array in the response, no matter what id values I tried in the query. It got me to read about Elasticsearch query syntax, mapping, and I found out I needed to specify a mapping.
When the collection is created without specifying a mapping, document.search:
returns an empty array of hits if given a "query" body property such as the following:
{"query": {"terms": {"id": <ids array>}}}
throws the following if given a "sort":
// {"sort": [{"id": {"order": "desc"}}]} Error: No mapping found for [id] in order to sort on
and returns an empty bucket list for an "aggregations" like this :
"aggregations": { "groupById": { "terms": { "field": "id" } } }
I don't understand what is happening behind this. Is it normal that only one case is being treated as an error? I was working on the query part, and it was not obvious that the error didn't come from the content of my ids array!
Adding a simple mapping on "id" with the "keyword" type makes all cases work as intended, but I read about dynamic mappings in Elasticsearch. Is there a way to use them? Or is there another solution for querying a (the only) parameter in my document?
I'm using kuzzle-sdk v7.1.4
Many thanks!