On Mon, Dec 3, 2018 at 9:29 AM Burak Serdar <bser...@ieee.org> wrote:
>
> On Mon, Dec 3, 2018 at 9:06 AM Jeffrey Smith
> <jeffreysmith19...@gmail.com> wrote:
> >
> > That is 99% of what I'm after cheers.
> >
> > I need to be able to set the _doc bit to be any random  string if possible 
> > as its the type name.
> >
> > `json:"_doc"`
>
>
> Nested maps are messy to deal with. In my opinion, your best bet is a
> custom marshaler:
>
> type Doc struct {
>   Tag string
>   Properties ...
> }
>
> func (d Doc) MarshalJSON() ([]byte,err) {
>    
> m:=map[string]interface{}{d.Tag:map[string]interface{}{"properties":d.Properties}}
>   return json.Marshal(m)
> }
>
> I didn't test the syntax, but it should give you the idea.


Sorry, this is wrong, I realized after I sent it. Marshal should be
done for the struct containing Doc. You also have to change the
structures a bit to make it work:

https://play.golang.org/p/qF8PbgMNct9

>
> >
> > On Monday, December 3, 2018 at 3:53:34 PM UTC, Burak Serdar wrote:
> >>
> >> On Mon, Dec 3, 2018 at 8:27 AM Jeffrey Smith
> >> <jeffreys...@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...@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