ElasticSearch RegExp Filter regex dash
Problem:
This is because the default analyzer usually tokenizes at -
, so your field is most likey saved like:
MD01575254
40
BlUE
Solution:
You can update your mapping to have a sku.raw
field that would not be analyzed when indexed. This will require you to delete and re-index.
{ "<type>" : { "properties" : { ..., "sku" : { "type": "string", "fields" : { "raw" : {"type" : "string", "index" : "not_analyzed"} } } } }}
Then you can query this new field which is not analyzed:
{ "query" : { "regexp" : { "sku.raw": "md01575254-40.*" } }}
HTTP Endpoints:
The API to delete your current mapping and data is:
DELETE http://localhost:9200/<index>/<type>
The API to add your new mapping, with the raw SKU is:
PUT http://localhost:9200/<index>/<type>/_mapping
Links:
This can also we achieved by the following query. (use .keyword
next to the field)
"regexp": {"sku.keyword": "md01575254-40.*"}