# Combine wildcard and exact match

**URL:** <https://discuss.elastic.co/t/combine-wildcard-and-exact-match/135678>\
**Category:** Elasticsearch\
**Created:** [June 13, 2018, 10:11am UTC](https://discuss.elastic.co/t/combine-wildcard-and-exact-match/135678 "2018-06-13T10:11:06Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anand\_V](https://avatars.discourse-cdn.com/v4/letter/a/ed655f/32.png) [@Anand\_V](https://discuss.elastic.co/u/Anand_V)\
**Post date:** [June 13, 2018, 10:11am UTC](https://discuss.elastic.co/t/combine-wildcard-and-exact-match/135678/1 "2018-06-13T10:11:06Z")

</div>

I am new to querying in elasticsearch. I am trying to match a field with wildcard and a few more fields with exact match. I am not able to form a proper query. Can someone help me?

---

<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:** [June 13, 2018, 10:29am UTC](https://discuss.elastic.co/t/combine-wildcard-and-exact-match/135678/2 "2018-06-13T10:29:05Z")

</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 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:** ![Anand\_V](https://avatars.discourse-cdn.com/v4/letter/a/ed655f/32.png) [@Anand\_V](https://discuss.elastic.co/u/Anand_V)\
**Post date:** [June 13, 2018, 10:55am UTC](https://discuss.elastic.co/t/combine-wildcard-and-exact-match/135678/3 "2018-06-13T10:55:57Z")

</div>

The following gives me appropriate search where my index is tracking-number-details:

`http://localhost:9200/tracking-number-details/_search?q=*w333ny8*&size=1000`

But I need to search a few more fields to match. I tried the following:

```
{
	"size" : 1000,
	"bool": {
	      "should": [
	     	{ "match": {"number":"84W333" }},
	        {"match": {"client_id":"21" }}]
	      },
	   "query" :{
		
			"wildcard" : {
            				"tracking_number": "*w333ny82441914*"
	    				}
	    
}
}

```

but it gives error:  
{"error":{"root\_cause":[{"type":"parsing\_exception","reason":"Unknown key for a START\_OBJECT in [bool].","line":3,"col":10}],"type":"parsing\_exception","reason":"Unknown key for a START\_OBJECT in [bool].","line":3,"col":10},"status":400}

I tried even this:

```
{
	
	"query" :{
	      "multi_match": {
            "query": "1Z84W333NW* 84W333 21",
       "type": "cross_fields",
       "analyzer": "standard",
       "fields": ["tracking_number^3","number","client_id"]
   }
}
}

```

But it gives matches of 1Z84W333NW\* which are partial to this text. I need help to figure better to write.

---

<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:** [June 13, 2018, 12:23pm UTC](https://discuss.elastic.co/t/combine-wildcard-and-exact-match/135678/4 "2018-06-13T12:23:35Z")

</div>

2 comments:

- Your text is not correctly formatted as per instructions I linked to
- I can not copy and paste what you posted to test it in Kibana, as per instructions.

Please [follow the instructions](https://discuss.elastic.co/t/about-the-elasticsearch-category/21) if you need help.

---

<div class="post-metadata">

**Author:** ![Anand\_V](https://avatars.discourse-cdn.com/v4/letter/a/ed655f/32.png) [@Anand\_V](https://discuss.elastic.co/u/Anand_V)\
**Post date:** [June 13, 2018, 12:33pm UTC](https://discuss.elastic.co/t/combine-wildcard-and-exact-match/135678/5 "2018-06-13T12:33:12Z")

</div>

I have edited as you asked. If I still need me to do something more, please suggest

---

<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:** [June 13, 2018, 12:49pm UTC](https://discuss.elastic.co/t/combine-wildcard-and-exact-match/135678/6 "2018-06-13T12:49:37Z")

</div>

I can not copy and paste what you posted to test it in Kibana.

I don't have any data to play with.

To explain more. This is useless:

```auto
{
	"size" : 1000,
	"bool": {
	      "should": [
	     	{ "match": {"number":"84W333" }},
	        {"match": {"client_id":"21" }}]
	      },
	   "query" :{
		
			"wildcard" : {
            				"tracking_number": "*w333ny82441914*"
	    				}
	    
}
}

```

This is useful:

```auto
DELETE index
PUT index/_doc/1
{
  "foo": "bar"
}
GET index/_search
{
  "query": {
    "match": {
      "foo": "bar"
    }
  }
}

```

See the difference?

---

<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:** [July 11, 2018, 12:49pm UTC](https://discuss.elastic.co/t/combine-wildcard-and-exact-match/135678/7 "2018-07-11T12:49:38Z")

</div>

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