我正在使用searchkit 2.2.0中的 SearchBox ,并希望将选项类型为best_fields 的多重匹配查询发送到elasticsearch。
如果我设置 prefixQueryFields 属性,查询是我想要的多重匹配,但是类型是phrase_prefix得到我不喜欢的结果。 QueryAccessor.ts->this.options.prefixQueryFields->type:"phrase_prefix"
<SearchBox autofocus={true} searchOnChange={true} prefixQueryFields={["fileName^3", "path", "attachment.content", "attachment.author", "attachment.title"]}/>
如果我设置 prefixQueryOptions 属性,为了避免输入phrase_prefix类型,查询将变为simple_query_string。当我设置 prefixQueryOptions 对象时,也许我在这里犯了一个错误。
<SearchBox autofocus={true} searchOnChange={true} prefixQueryOptions={{
"fields" : [ "fileName^3", "path", "attachment.content", "attachment.author", "attachment.title" ],
"type": "best_fields"
}}/>
答案 0 :(得分:0)
queryBuilder 可以提供比 prefixQueryFields 更灵活的逻辑。 https://blog.searchkit.co/searchkit-0-9-23d78568d219
const customQueryBuilder = (query, options) => {
return {
"multi_match": {
"query": query,
"fields" : [ "fileName^3", "path", "attachment.content", "attachment.author", "attachment.title" ],
"type": "best_fields"
}
}
}
<SearchBox autofocus={true} searchOnChange={true} queryOptions={{analyzer:"standard"}} queryFields={["fileName^3","path","attachment.content","attachment.author","attachment.title","attachment.fileExtension"]} queryBuilder={customQueryBuilder} />