问题描述
我正在使用Searchkit 2.2.0中的 SearchBox ,并且想对带有弹性搜索的 multi Match Query 和选项 type best_fields 进行. >
I am using SearchBox from searchkit 2.2.0 and would like to make Multi Match Query with option type best_fields to elasticsearch.
- 当我使用 prefixQueryFields 时如何设置 type best_fields ?
- 如何正确设置具有 type best_fields 类型的 prefixQueryOptions 对象?
- How to set type best_fields when I use prefixQueryFields?
- How to correctly set prefixQueryOptions object with type best_fields?
如果我设置了 prefixQueryFields 属性,则查询是我想要的多匹配项,但类型是phrase_prefix使我得到非期望的结果. QueryAccessor.ts-> this.options.prefixQueryFields->类型:"phrase_prefix"
If I set prefixQueryFields attribute, query is Multi Match as I want, but type is phrase_prefix gets me non prefered results.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 对象时,我可能在这里犯了一个错误.
If I set prefixQueryOptions attribute, to avoid type phrase_prefix, query become just simple_query_string. Maybe I made a mistake here, when I set prefixQueryOptions object.
<SearchBox autofocus={true} searchOnChange={true} prefixQueryOptions={{
"fields" : [ "fileName^3", "path", "attachment.content", "attachment.author", "attachment.title" ],
"type": "best_fields"
}}/>
推荐答案
queryBuilder 可以提供比 prefixQueryFields 更灵活的逻辑. https://blog.searchkit.co/searchkit-0-9-23d78568d219
queryBuilder can provide more flexible logic than 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} />
这篇关于SearchBox多重比对查询,类型为best_fields,而非NOT_PREFIX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!