SearchBox多重匹配查询,类型为best_fields而非phrase_prefix

时间:2017-10-11 10:08:39

标签: reactjs elasticsearch searchkit

我正在使用searchkit 2.2.0中的 SearchBox ,并希望将选项类型为best_fields 多重匹配查询发送到elasticsearch。

  1. 当我使用 prefixQueryFields 时,如何设置输入best_fields
  2. 如何使用类型best_fields 正确设置 prefixQueryOptions 对象?
  3. 如果我设置 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"]}/>
    result query: prefixQueryFields and type phrase_prefix

    如果我设置 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"
    			}}/>
    result query: prefixQueryOptions and simple_query_string

    search-box

    multi-match-types

1 个答案:

答案 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} />

enter image description here