# Multi field search with wildcard expression in query

**URL:** <https://discuss.elastic.co/t/multi-field-search-with-wildcard-expression-in-query/258001>\
**Category:** Elasticsearch\
**Created:** [December 8, 2020, 1:53pm UTC](https://discuss.elastic.co/t/multi-field-search-with-wildcard-expression-in-query/258001 "2020-12-08T13:53:51Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![sreedhar1](https://avatars.discourse-cdn.com/v4/letter/s/dc4da7/32.png) [@sreedhar1](https://discuss.elastic.co/u/sreedhar1)\
**Post date:** [December 8, 2020, 1:53pm UTC](https://discuss.elastic.co/t/multi-field-search-with-wildcard-expression-in-query/258001/1 "2020-12-08T13:53:51Z")

</div>

Expecting text "abc" search against field1 or field2 to get the results.  
what is wrong in below query?  
s =\> s  
.Query(q =\> q  
.DisMax(d =\> d  
.Queries(q1 =\> q1  
.Wildcard(w =\> w  
.Field(f =\> f.field1).Value("abc\*")  
.Field(f =\> f.field2).Value("abc\*")  
)  
)))

tried this as well:

s =\> s  
.Query(q =\> q  
.Bool(d =\> d  
.Must(q1 =\> q1  
.Wildcard(w =\> w  
.Field(f1 =\> f1.field1).Value("abc\*")  
.Field(f =\> f.field2).Value("abc\*")  
)  
))));

its working only for field2 search.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [December 8, 2020, 3:27pm UTC](https://discuss.elastic.co/t/multi-field-search-with-wildcard-expression-in-query/258001/2 "2020-12-08T15:27:27Z")

</div>

Could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script is something anyone can copy and paste in Kibana dev console, click on the run button to reproduce your use case. It will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

---

<div class="post-metadata">

**Author:** ![sreedhar1](https://avatars.discourse-cdn.com/v4/letter/s/dc4da7/32.png) [@sreedhar1](https://discuss.elastic.co/u/sreedhar1)\
**Post date:** [December 10, 2020, 7:07am UTC](https://discuss.elastic.co/t/multi-field-search-with-wildcard-expression-in-query/258001/3 "2020-12-10T07:07:59Z")

</div>

Thank you for your response.

I am new to Elasticsearch, i have installed elasticsearch and logstash in my machine.  
i have pushed data to elastic search.

Using Nest elastic client i am searching data in elasticsearch data.

My requirement is i want to do like search against two columns.

Using below client query i am able to search data in one column (column name is accno).

var searchResult = client.Search(s =\> s  
.Query(q =\> q  
.Wildcard(m =\> m  
.Field(f =\> f.Accno)  
.Value("TS18\*")))  
.Size(50));

Now i want to search value "TS18\*" against accno and reqno fields. I am unable to write  
single query to search in two fields.

Thank you for your help.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [December 10, 2020, 7:29am UTC](https://discuss.elastic.co/t/multi-field-search-with-wildcard-expression-in-query/258001/4 "2020-12-10T07:29:43Z")

</div>

Have a look at the link I shared. I can't help without a minimal set of information.  
I don't write dotNet code so using Kibana dev console would help.

---

<div class="post-metadata">

**Author:** ![sreedhar1](https://avatars.discourse-cdn.com/v4/letter/s/dc4da7/32.png) [@sreedhar1](https://discuss.elastic.co/u/sreedhar1)\
**Post date:** [December 10, 2020, 2:57pm UTC](https://discuss.elastic.co/t/multi-field-search-with-wildcard-expression-in-query/258001/5 "2020-12-10T14:57:57Z")

</div>

hope this helps for you to understand my issue.  
GET index\_name/\_search  
{  
"query": {  
"wildcard": {  
"foo": "bar\*"  
}  
}  
}

foo and foo1 are the fields in my index.  
now i want to search "bar\*" in foo, foo1 fields.  
how to write query to search the same value in two fields?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [December 10, 2020, 3:12pm UTC](https://discuss.elastic.co/t/multi-field-search-with-wildcard-expression-in-query/258001/6 "2020-12-10T15:12:04Z")

</div>

Use the `multi_match` query or a bool query with a `should` array with two `wildcard` queries.  
But I'd not use wildcards unless I don't care of the response time.

---

<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:** [January 7, 2021, 3:12pm UTC](https://discuss.elastic.co/t/multi-field-search-with-wildcard-expression-in-query/258001/7 "2021-01-07T15:12:07Z")

</div>

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