在Elasticsearch for Go中的ContextQueries for Completion建议程序中传递什么参数?

时间:2019-05-07 12:00:59

标签: elasticsearch go

我正在尝试为Go的Elasticsearch中的完成建议添加上下文。我正在为Go使用Olivere的elasticsearch库,但无法确定必须传递给 ContextQueries() 的参数。我可以看到它需要一种 SuggesterContextQuery 类型,但是我不确定如何制作。

我尝试过docs,但我仍然不清楚。

func (q *CompletionSuggester) ContextQueries(queries ...SuggesterContextQuery) *CompletionSuggester {
    q.contextQueries = append(q.contextQueries, queries...)
    return q
}
type SuggesterContextQuery interface {
    Source() (interface{}, error)
}

这是我的代码

sugg := "sticker-suggest"
tagSuggester := elastic.NewCompletionSuggester(sugg).Fuzziness(0).Text(term).Field("tags").SkipDuplicates(true)

searchSource := elastic.NewSearchSource().
    Suggester(tagSuggester).
    FetchSource(false).
    TrackScores(true)

searchResult, err := client.Search().
    Index(index).
    Type(Type).
    SearchSource(searchSource).
    Do(ctx)

如何为完成提示添加上下文?

0 个答案:

没有答案