【问题标题】:SearchBox Multi Match Query with type best_fields and NOT phrase_prefixSearchBox 多匹配查询,类型为 best_fields 而不是短语前缀
【发布时间】:2017-10-11 10:08:38
【问题描述】:

我正在使用 searchkit 2.2.0 中的 SearchBox,并希望使用选项 type best_fieldsMulti Match Query 设置为 elasticsearch。 p>

  1. 当我使用prefixQueryFields时如何设置type best_fields
  2. 如何正确设置 prefixQueryOptions 对象 type best_fields

如果我设置 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"
			}}/>

search-box

multi-match-types

【问题讨论】:

    标签: reactjs elasticsearch searchkit


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2018-04-21
      • 1970-01-01
      • 1970-01-01
      • 2020-11-28
      • 1970-01-01
      • 1970-01-01
      • 2015-07-13
      • 2014-10-21
      • 2018-03-23
      相关资源
      最近更新 更多