I would like to ask which boss has used the github.com/olivere/elastic package to operate ElasticSearch?

query: = elastic.NewTermQuery ("category_id", categoryId)
result, e: = ES.GetEs (). Search (). Index ("group_category"). Type ("_ doc") .query (query) .sort ("img_date", false) .Do (context.Background ())

in this way, the search returns all the fields. I want to return only the specified fields. How should I set them? For example, I just want to return to the id field and ask for guidance from all of you!


package main

import (
    "fmt"
    "github.com/olivere/elastic"
    "golang.org/x/net/context"
)

func main() {
    client, err := elastic.NewClient(
        elastic.SetURL("your es"),
    )
    if err != nil {
        // Handle error
    }

    fsc := elastic.NewFetchSourceContext(true).Include("field1", "field12") //.Exclude("*.description")
    query := elastic.NewTermQuery("category_id", 1)

    result, err := client.Search().
        Index("yourindex").
        Type("yourtype").
        Query(query).
        FetchSourceContext(fsc).
        Sort("img_date", false).
        Pretty(true).
        Do(context.Background())
    if err != nil {
        panic(err)
    }

    for i, r := range result.Hits.Hits {
        fmt.Println(i, string(*r.Source))
    }
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e84dfd-d17.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e84dfd-d17.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?