![](/img/trans.png)
[英]Failed to create query: Can only use phrase prefix queries on text fields - not on [customer_name] which is of type [keyword]
[英]SearchBox Multi Match Query with type best_fields and NOT phrase_prefix
我正在使用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" }}/>
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} />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.