# Creating a raw field mapping searchable by regexes with spaces

**URL:** https://discuss.elastic.co/t/creating-a-raw-field-mapping-searchable-by-regexes-with-spaces/243117
**Category:** Elasticsearch
**Created:** [July 29, 2020, 7:56pm UTC](https://discuss.elastic.co/t/creating-a-raw-field-mapping-searchable-by-regexes-with-spaces/243117 "2020-07-29T19:56:18Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Supermathie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/supermathie/32/44936_2.png) [@Supermathie](https://discuss.elastic.co/u/Supermathie)
#### Post date: [July 29, 2020, 7:56pm UTC](https://discuss.elastic.co/t/creating-a-raw-field-mapping-searchable-by-regexes-with-spaces/243117/1 "2020-07-29T19:56:18Z")

</div>

On Elastic 6.6, I'm trying to create an index that supports a regex search when the regex has spaces in it.

I see older references to [`not_analyzed`](https://stackoverflow.com/q/18235996/93180) that no longer apply to modern versions of Elasticsearch.

I've tried, for example:

```auto
PUT /_template/other
{
  "index_patterns": ["other", "other-*"],
  "mappings": {
    "other": {
      "properties": {
        "message": {
          "index": true,
          "type": "text",
          "fields": {
            "raw": {
              "type": "text",
              "analyzer": "keyword"
            }
          }
        }
      }
    }
  }
}

```

and variations:

```auto
            "raw": {
              "type": "keyword"
            }

```

but can't figure out how to get it to work with a simple document like:

```auto
POST /other-testing/other
{
  "message": "hello there I'm testing spaces"
}

```

and a search such as:

```auto
{
  "regexp": {
    "message": {
      "value": ".*testing .*"
    }
  }
}

```

---

<div class="post-metadata">

### Author: ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)
#### Post date: [August 3, 2020, 8:59am UTC](https://discuss.elastic.co/t/creating-a-raw-field-mapping-searchable-by-regexes-with-spaces/243117/2 "2020-08-03T08:59:26Z")

</div>

The problem is you create a variant of the field called "raw" but didn't refer to it in the query by it's name (`message.raw`).  
Working example below:

```
DELETE test
PUT test
{
  "mappings": {
	"_doc": {
	  "properties": {
		"message": {
		  "type": "text"
		  ,"fields":{
			"raw":{
			  "type":"keyword"
			}
		  }
		}
	  }
	}
  }
}
POST test/_doc/1
{
  "message":"hello there I'm testing spaces"
}
GET test/_search
{
  "query": {
	"regexp": {
	  "message.raw": {
		"value": ".*testing .*"
	  }
	}
  }
}
```

---

<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: [August 31, 2020, 8:59am UTC](https://discuss.elastic.co/t/creating-a-raw-field-mapping-searchable-by-regexes-with-spaces/243117/3 "2020-08-31T08:59:29Z")

</div>

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