Elasticsearch wildcard keyword * not working

mapping

{
	"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

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

result

{
  "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

{
	"_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": [
			"工号"
		]
	}
}

Try;

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,

Thank you, the problem has been resolved

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