# Elasticsearch wildcard keyword \* not working

**URL:** https://discuss.elastic.co/t/elasticsearch-wildcard-keyword-not-working/330361
**Category:** Elasticsearch
**Created:** [April 20, 2023, 7:48am UTC](https://discuss.elastic.co/t/elasticsearch-wildcard-keyword-not-working/330361 "2023-04-20T07:48:11Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![jiankunking](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jiankunking/32/39320_2.png) [@jiankunking](https://discuss.elastic.co/u/jiankunking)
#### Post date: [April 20, 2023, 7:48am UTC](https://discuss.elastic.co/t/elasticsearch-wildcard-keyword-not-working/330361/1 "2023-04-20T07:48:11Z")

</div>

mapping

```auto
{
	"jiankunking-dev": {
		"mappings": {
			"dynamic_templates": [
				{
					"strings": {
						"match_mapping_type": "string",
						"mapping": {
							"type": "keyword"
						}
					}
				}
			],
			"properties": {
				"attrs": {
					"properties": {
						"user_id": {
							"properties": {
								"almScode": {
									"type": "keyword"
								},
								"attrDesc": {
									"type": "keyword"
								},
								"attrType": {
									"type": "keyword"
								},
								"attrValue": {
									"type": "keyword"
								}
							}
						}
					}
				},
				"createdAt": {
					"type": "date",
					"format": "epoch_second"
				},
				"creator": {
					"type": "keyword"
				},
				"id": {
					"type": "keyword"
				},
				"updateAt": {
					"type": "long"
				},
				"updatedAt": {
					"type": "date",
					"format": "epoch_second"
				},
				"updater": {
					"type": "keyword"
				}
			}
		}
	}
}

```

but

query

```auto
GET jiankunking-dev/_search
{
  "query": {
    "bool": {
      "minimum_should_match": "1",
      "should": [
        {
          "wildcard": {
            "attrs.user_id.attrValue.keyword": {
              "value": "20000000"
            }
          }
        }
      ]
    }
  }
}

```

result

```auto
{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 6,
    "successful" : 6,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 0,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : []
  }
}

```

But there are 20000000 pieces of data in ES

```auto
{
	"_index": "jiankunking-dev",
	"_type": "_doc",
	"_id": "20000000",
	"_version": 10,
	"_score": 0,
	"fields": {
		"attrs.user_id.attrValue": [
			"20000000"
		],
		"id": [
			"20000000"
		],
		"attrs.user_id.attrType": [
			"String"
		],
		"attrs.user_id.attrDesc": [
			"工号"
		]
	}
}

```

---

<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: [April 20, 2023, 7:49am UTC](https://discuss.elastic.co/t/elasticsearch-wildcard-keyword-not-working/330361/2 "2023-04-20T07:49:58Z")

</div>

Try;

```auto
GET jiankunking-dev/_search
{
  "query": {
    "bool": {
      "minimum_should_match": "1",
      "should": [
        {
          "wildcard": {
            "attrs.user_id.attrValue": {
              "value": "20000000"
            }
          }
        }
      ]
    }
  }
}

```

You don't need to add `.keyword` to the end of the field if it is mapped as a keyword,

---

<div class="post-metadata">

### Author: ![jiankunking](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jiankunking/32/39320_2.png) [@jiankunking](https://discuss.elastic.co/u/jiankunking)
#### Post date: [April 20, 2023, 9:00am UTC](https://discuss.elastic.co/t/elasticsearch-wildcard-keyword-not-working/330361/3 "2023-04-20T09:00:11Z")

</div>

Thank you, the problem has been resolved

---

<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: [May 18, 2023, 9:00am UTC](https://discuss.elastic.co/t/elasticsearch-wildcard-keyword-not-working/330361/4 "2023-05-18T09:00:17Z")

</div>

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