# Regex/Wildcard Query not working

**URL:** <https://discuss.elastic.co/t/regex-wildcard-query-not-working/99775>\
**Category:** Elasticsearch\
**Created:** [September 8, 2017, 12:36am UTC](https://discuss.elastic.co/t/regex-wildcard-query-not-working/99775 "2017-09-08T00:36:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pritom\_Ahmed](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pritom_ahmed/32/20783_2.png) [@Pritom\_Ahmed](https://discuss.elastic.co/u/Pritom_Ahmed)\
**Post date:** [September 8, 2017, 12:36am UTC](https://discuss.elastic.co/t/regex-wildcard-query-not-working/99775/1 "2017-09-08T00:36:15Z")

</div>

Hi,

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

```
SearchResponse response = client.prepareSearch("index")
                .setTypes("log")
                .setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
                .setQuery(QueryBuilders.rangeQuery(time").gte(100000))
                .setQuery(QueryBuilders.regexpQuery("path", "first*second"))
                .setFrom(0).setSize(10).setExplain(true)
                .get();

```

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 ?

Thanks

---

<div class="post-metadata">

**Author:** ![Pritom\_Ahmed](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pritom_ahmed/32/20783_2.png) [@Pritom\_Ahmed](https://discuss.elastic.co/u/Pritom_Ahmed)\
**Post date:** [September 8, 2017, 7:07pm UTC](https://discuss.elastic.co/t/regex-wildcard-query-not-working/99775/2 "2017-09-08T19:07:46Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 6, 2017, 7:38pm UTC](https://discuss.elastic.co/t/regex-wildcard-query-not-working/99775/4 "2017-10-06T19:38:53Z")

</div>

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