In addition to Burak's suggestion, keep in mind that if you implement
MarshalJSON and/or UnmarshalJSON for certain structs, then those will be
used instead of the built-in functions. If you end up cleaning up your
struct definitions and just cant find the right way to annotate your fields
to get the behavior you want, then that might be your best bet.

example is in godoc at https://golang.org/pkg/encoding/json/ under
CustomMarshalJSON

Diane Looney


On Mon, Dec 3, 2018 at 10:53 AM Burak Serdar <bser...@ieee.org> wrote:

> On Mon, Dec 3, 2018 at 8:27 AM Jeffrey Smith
> <jeffreysmith19...@gmail.com> wrote:
> >
> > I'm trying to set mapping in elastic search in go and want to generate
> something like this.
> >
> > { "mappings": { "_doc": { "properties": { "title": { "type": "text",
> "store": true }, "date": { "type": "date", "store": true }, "content": {
> "type": "text" } } } } }
> >
>
> Is this close to what you're trying to do:
>
> https://play.golang.org/p/wYOwf6wUai7
>
> >
> > The _doc, title,date and content are all keys that will change depending
> on what mapping I am trying to generate.
> >
> > I have a basic struct layout but cant work out how to generate the
> proper JSON.
> >
> > type mappingData struct {
> >         Mappings struct {
> >                 Doc struct {
> >                         Properties struct {
> >                                 Elements []Fields
> >                         } `json:"properties"`
> >                 } `json:"_doc"`
> >         } `json:"mappings"`
> > }
> >
> >
> > type Fields struct {
> >         Type  string `json:"type"`
> >         Store bool   `json:"store"`
> > }
> >
> > _doc will be from a string and I have a vector of structs that has
> different fields in.
> >
> > --
> > You received this message because you are subscribed to the Google
> Groups "golang-nuts" group.
> > To unsubscribe from this group and stop receiving emails from it, send
> an email to golang-nuts+unsubscr...@googlegroups.com.
> > For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to