2

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?

4
  • where is the prefix query in your search query? You seem to be doing a query_string query? Commented Jul 10, 2017 at 6:12
  • @RussCam This is first time i am using elastic search and not sure why i am getting error like that. May be because my searchText variable has wildcard value like "price level". Commented Jul 12, 2017 at 15:52
  • @Sandeep Did you a get a fix for this issue? Commented Oct 12, 2018 at 10:05
  • 1
    final SimpleQueryStringBuilder queryBuilder = simpleQueryStringQuery(query) .field("*") // search all fields .analyzeWildcard(true).setLenient(true); // analyze wildcard to handle number based fields Maybe this helps Commented Jan 26, 2020 at 9:49

1 Answer 1

0

In my case this occurred when i perform search with spacial character.

I fixed this with following,

Elasticsearch - v6.8.6

Map<String, Float> fields = new HashMap<>();
        fields.put("content.keyword", 1f);
        fields.put("name.keyword", 2f);
        fields.put("tag.keyword", 3f);

SimpleQueryStringBuilder queryBuilder = new SimpleQueryStringBuilder(searchQuery);
queryBuilder.fields(fields);
queryBuilder.analyzeWildcard(Boolean.TRUE);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.