# Query\_string and wildcards behaves incorrectly?

**URL:** <https://discuss.elastic.co/t/query-string-and-wildcards-behaves-incorrectly/42981>\
**Category:** Elasticsearch\
**Created:** [February 29, 2016, 8:58am UTC](https://discuss.elastic.co/t/query-string-and-wildcards-behaves-incorrectly/42981 "2016-02-29T08:58:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christoph\_Seiler](https://avatars.discourse-cdn.com/v4/letter/c/3da27b/32.png) [@Christoph\_Seiler](https://discuss.elastic.co/u/Christoph_Seiler)\
**Post date:** [February 29, 2016, 8:58am UTC](https://discuss.elastic.co/t/query-string-and-wildcards-behaves-incorrectly/42981/1 "2016-02-29T08:58:29Z")

</div>

So for a client we created an editor to define filters via an UserInterface. The Queries "work" but for at least one case where it's strangely incorrect:

We want a 'real' contains so that if we are searching in "youtube videos", we hit: tub, tube, youtube and youtube videos ...

the approach is the following:

```
Base Query:
{
  "query": {
	"filtered": {
	  "query": {
		"bool": {
		  "must": [
			{
			  "bool": {
				"should": [
				  {
					"query_string": {
					  "default_field": "activityType_de",
					  "query": "*tub*",
					  "boost": 1.0
					}
				  }
				],
				"minimum_should_match": 1
			  }
			}
		  ]
		}
	  }
	}
  },
  "size": 50
}

Result is:
{
	"took": 2,
	"timed_out": false,
	"_shards": {
		"total": 1,
		"successful": 1,
		"failed": 0
	},
	"hits": {
		"total": 1,
		"max_score": 1,
		"hits": [
			{
				"_index": "simple",
				"_type": "activity",
				"_id": "Activity_235",
				"_score": 1,
				"_source": {
					...
					"activityType_de": "youtube video",
					"activityType_en": "youtube video",
					"activityType_it": "youtube video",
					"activityType_fr": "vidéo youtube",
					"activityType": "508",
					...
					"name": "video nummer 1",
				}
			}
		]
	}
}

which is correct, but if we search for youtube:
{
  "query": {
	"filtered": {
	  "query": {
		"bool": {
		  "must": [
			{
			  "bool": {
				"should": [
				  {
					"query_string": {
					  "default_field": "activityType_de",
					  "query": "*youtube*",
					  "boost": 1.0
					}
				  }
				],
				"minimum_should_match": 1
			  }
			}
		  ]
		}
	  }
	}
  },
  "size": 50
}

we get zero hits.

"query": "youtube" -> works
"query": "*youtube*" -> does not work
"query": "tube" -> does not work
"query": "*tube" -> does not work
"query": "*tube*" -> does not work
"query": "*tub*" -> works

```

Can anybody tell me where my mistake is?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [February 29, 2016, 9:01am UTC](https://discuss.elastic.co/t/query-string-and-wildcards-behaves-incorrectly/42981/2 "2016-02-29T09:01:41Z")

</div>

I think you need to wrap your code in the proper formatting, all we can see is italics.

---

<div class="post-metadata">

**Author:** ![Christoph\_Seiler](https://avatars.discourse-cdn.com/v4/letter/c/3da27b/32.png) [@Christoph\_Seiler](https://discuss.elastic.co/u/Christoph_Seiler)\
**Post date:** [February 29, 2016, 9:11am UTC](https://discuss.elastic.co/t/query-string-and-wildcards-behaves-incorrectly/42981/3 "2016-02-29T09:11:34Z")

</div>

better?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [February 29, 2016, 9:32am UTC](https://discuss.elastic.co/t/query-string-and-wildcards-behaves-incorrectly/42981/4 "2016-02-29T09:32:47Z")

</div>

Yeah, thanks!  
FYI using a `*foobar*` search is seriously inefficient, it's akin to a table scan.

Are you setting specific mappings on the various `activityType_` fields?

---

<div class="post-metadata">

**Author:** ![Christoph\_Seiler](https://avatars.discourse-cdn.com/v4/letter/c/3da27b/32.png) [@Christoph\_Seiler](https://discuss.elastic.co/u/Christoph_Seiler)\
**Post date:** [February 29, 2016, 9:49am UTC](https://discuss.elastic.co/t/query-string-and-wildcards-behaves-incorrectly/42981/5 "2016-02-29T09:49:18Z")

</div>

Yeap:

```
{
  "simple" : {
    "mappings" : {
      "_default_" : {
        "dynamic_templates" : [ {
          "de" : {
            "mapping" : {
              "analyzer" : "german",
              "type" : "string"
            },
            "match" : "*_de",
            "match_mapping_type" : "string"
          }
        }, {
          "en" : {
            "mapping" : {
              "analyzer" : "english",
              "type" : "string"
            },
            "match" : "*_en",
            "match_mapping_type" : "string"
          }
        }, {
          "it" : {
            "mapping" : {
              "analyzer" : "italian",
              "type" : "string"
            },
            "match" : "*_it",
            "match_mapping_type" : "string"
          }
        }, {
          "fr" : {
            "mapping" : {
              "analyzer" : "french",
              "type" : "string"
            },
            "match" : "*_fr",
            "match_mapping_type" : "string"
          }
        } ],
        "properties" : { }
      },
      "activity" : {
        "dynamic_templates" : [ {
          "de" : {
            "mapping" : {
              "analyzer" : "german",
              "type" : "string"
            },
            "match" : "*_de",
            "match_mapping_type" : "string"
          }
        }, {
          "en" : {
            "mapping" : {
              "analyzer" : "english",
              "type" : "string"
            },
            "match" : "*_en",
            "match_mapping_type" : "string"
          }
        }, {
          "it" : {
            "mapping" : {
              "analyzer" : "italian",
              "type" : "string"
            },
            "match" : "*_it",
            "match_mapping_type" : "string"
          }
        }, {
          "fr" : {
            "mapping" : {
              "analyzer" : "french",
              "type" : "string"
            },
            "match" : "*_fr",
            "match_mapping_type" : "string"
          }
        } ],
        "properties" : {
		  ...,
          "activityType" : {
            "type" : "string",
            "index" : "not_analyzed"
          },
          "activityType_de" : {
            "type" : "string",
            "analyzer" : "german"
          },
          "activityType_en" : {
            "type" : "string",
            "analyzer" : "english"
          },
          "activityType_fr" : {
            "type" : "string",
            "analyzer" : "french"
          },
          "activityType_it" : {
            "type" : "string",
            "analyzer" : "italian"
          },
		  ...,
          "name" : {
            "type" : "string",
            "index" : "not_analyzed"
          }
        }
      }
    }
  }
}
```

---

<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 5, 2017, 11:12pm UTC](https://discuss.elastic.co/t/query-string-and-wildcards-behaves-incorrectly/42981/6 "2017-07-05T23:12:54Z")

</div>


