0

I am using SearchBox from searchkit 2.2.0 and would like to make Multi Match Query with option type best_fields to elasticsearch.

  1. How to set type best_fields when I use prefixQueryFields?
  2. How to correctly set prefixQueryOptions object with type best_fields?

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"]}/>
result query: prefixQueryFields and type phrase_prefix

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"
   }}/>
result query: prefixQueryOptions and simple_query_string

search-box

multi-match-types

Denis P.
  • 302
  • 1
  • 2
  • 8

1 Answers1

0

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

enter image description here

Denis P.
  • 302
  • 1
  • 2
  • 8