Regex/Wildcard Query not working

(Pritom Ahmed) #1


I am using the java API to query for a field with elasticsearch 5.5

SearchResponse response = client.prepareSearch("index")
                .setQuery(QueryBuilders.regexpQuery("path", "first*second"))

I have also tried wildcardQuery instead of regexQuery. The rangeQuery works fine on its own.

Now I know for sure that the path has value like "first,first,first,thirdsecond,"

Mapping for that field is as follows

> "path" : {
>             "type" : "text",
>             "fields" : {
>               "keyword" : {
>                 "type" : "keyword",
>                 "ignore_above" : 256
>               }
>             }
>           }, 

I can find results if I look for only one term like "first" or "second". My best guess is that the field is analyzed by standard analyzer and the value is tokenized. How can I prevent it ?

Also How can I add some return fields in the response like the SQL like select A, B, C ?


(Pritom Ahmed) #2

It looks like I needed to run the query against the "path.keyword" field instead of against the "path" field.

Thanks @abdon

Also addDocValueField(String name) does the select stuff. Just put the fields that you want to return in the parameter of the function.

(system) #4

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.