Searching values in multiple fields is not working when search text contains space. For example if i search for value "price" than i get results but if i search for "price level" than i get following error:
Can only use prefix queries on keyword and text fields - not on which is of type float
I have one date field and one float field in indexed documents. And error is thrown because of this fields.
Following is my code of creating Index:
var createIndexResponse = client.CreateIndex("messages", c => c.Settings(s => s.NumberOfShards(1).NumberOfReplicas(0).Analysis(a => a.Analyzers(anl => anl.Custom("default", ca => ca.Tokenizer("whitespace").Filters(new List<string>() { "lowercase" }))))).Mappings(ms => ms.Map<Object>(m => m.Properties(p => p.Number(s => s.Name("id").Index(false)).Text(s => s.Name("displaytext").Index(false)).Text(s => s.Name("text").Index(false)).Text(s => s.Name("url").Index(false)).Date(d => d.Name("Search_ReceivedOn"))))));
Following is my search query:
Dim funcMust = New List(Of Func(Of Nest.QueryContainerDescriptor(Of Object), Nest.QueryContainer))()
funcMust.Add(Function(sh) sh.Term("From", UserID) Or sh.Term("To", UserID))
Dim resp = client.Search(Of Object)(Function(s) s.Index("messages").IgnoreUnavailable(True) _
.Query(Function(qry) qry.QueryString(Function(qs) qs.Fields("Search_*").Query(searchText).DefaultOperator(Nest.Operator.And))) _
.PostFilter(Function(pf) pf.Bool(Function(b) b.Must(funcMust))).From((pageIndex - 1) * pageSize).Take(pageSize).Source(Function(x) x.Includes(Function(f) f.Fields(fields))))
I have dynamic columns in indexed document so i can not use term queries with exact field names. Is there any way to search on all fields that starts with "Search_" without error i have mentioned above?
prefix
query in your search query? You seem to be doing aquery_string
query? – Russ Camfinal SimpleQueryStringBuilder queryBuilder = simpleQueryStringQuery(query) .field("*") // search all fields .analyzeWildcard(true).setLenient(true); // analyze wildcard to handle number based fields
Maybe this helps – SimonH