mattbaird/elastigo

Why does PutMapping need and instance and a MappingOptions

nickydonna opened this issue · 3 comments

Sorry to bother but I'm trying to use PutMapping but it needs both an instance annotated for json and elastic, and a Mappings Options. Can't it be that you need only one of those.

Even so, couldn't this be done by just using a json string??
If you need I can make the pull request
Thanks

hi @donnanicolas,

The thought was enforcing the use of a struct would be less error prone. I agree, it would be useful to have a json string version (without removing the struct based version). Thanks.

I'll do a pull request for the JSON string ([]byte) version as soon as I can. Now I'm using an empty struct for it. Sorry to "hack" through your efforts, but otherwise a simple function would have been 4 times longer.
Close this issue if you want, I'll referenced it in the pull request

I just ran into some surprising behavior here (surprising to me, at least); I don't understand what the MappingOptions can do, except provide mappings for fields that are not present in the struct (which seems to be of limited usefulness?)

I was hoping to be able to override the mappings for a subset of the fields in my struct, and allow the default behavior to control the remaining fields. However, it seems that the derived mappings take precedence over the ones I provide in the MappingObject. Is this intentional?

I ended up just serializing my MappingObject to JSON, and then passing the bytes to PutMappingFromJSON, but that felt wrong, like I had one foot inside the concerns of elastigo's internals, and one foot outside:

        body, jsonErr := json.Marshal(es.MappingForType("user", mapping))
        if jsonErr != nil {
            return jsonErr
        }
        err = c.PutMappingFromJSON(indexName, "user", body)