# Querying a not\_analyzed field returning analyzed results

**URL:** https://discuss.elastic.co/t/querying-a-not-analyzed-field-returning-analyzed-results/29714
**Category:** Elasticsearch
**Created:** [September 21, 2015, 3:57pm UTC](https://discuss.elastic.co/t/querying-a-not-analyzed-field-returning-analyzed-results/29714 "2015-09-21T15:57:15Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![aitchon](https://avatars.discourse-cdn.com/v4/letter/a/2bfe46/32.png) [@aitchon](https://discuss.elastic.co/u/aitchon)
#### Post date: [September 21, 2015, 3:57pm UTC](https://discuss.elastic.co/t/querying-a-not-analyzed-field-returning-analyzed-results/29714/1 "2015-09-21T15:57:15Z")

</div>

I set a template mapping for an index like this:

PUT \_template/test\_template  
{  
"template" : "testsites-\*",  
"mappings": {  
"type1": {  
"properties": {  
"testurl": {  
"type":"string",  
"index":"not\_analyzed"  
}  
}  
}  
}  
}

When I query the index for field testurl, I'm getting results like this:  
"aggregations": {  
"sites": {  
"doc\_count\_error\_upper\_bound": 574889,  
"sum\_other\_doc\_count": 41123279,  
"buckets": [  
{  
"key": "http",  
"doc\_count": 10190076  
},  
{  
"key": "index",  
"doc\_count": 3673145  
},

It seems like the field is still analyzed. When I do a get for the mapping of the index, I don't see the field as not\_analyzed. Is the template not working correctly? If so, why?

---

<div class="post-metadata">

### Author: ![msimos](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@msimos](https://discuss.elastic.co/u/msimos)
#### Post date: [September 21, 2015, 4:58pm UTC](https://discuss.elastic.co/t/querying-a-not-analyzed-field-returning-analyzed-results/29714/2 "2015-09-21T16:58:22Z")

</div>

Hi,

Did you re-index the data or delete your index, create a new index and add new data? Because just changing the template won't affect whats currently there. The template only adds the string as not\_analyzed when a new index is created. It has no affect on existing indexes.

---

<div class="post-metadata">

### Author: ![aitchon](https://avatars.discourse-cdn.com/v4/letter/a/2bfe46/32.png) [@aitchon](https://discuss.elastic.co/u/aitchon)
#### Post date: [September 21, 2015, 5:09pm UTC](https://discuss.elastic.co/t/querying-a-not-analyzed-field-returning-analyzed-results/29714/3 "2015-09-21T17:09:47Z")

</div>

I created a new index and added data.

---

<div class="post-metadata">

### Author: ![msimos](https://avatars.discourse-cdn.com/v4/letter/m/bb73d2/32.png) [@msimos](https://discuss.elastic.co/u/msimos)
#### Post date: [September 21, 2015, 5:32pm UTC](https://discuss.elastic.co/t/querying-a-not-analyzed-field-returning-analyzed-results/29714/4 "2015-09-21T17:32:53Z")

</div>

Did you actually create the template? The only thing I see wrong is your missing \_template:

```auto
PUT /_template/testtemplate
{
  "template": "testsites-*",
  "mappings": {
    "type1": {
      "properties": {
        "testurl": {
          "type": "string",
          "index": "not_analyzed"
        }
      }
    }
  }
}
GET /_template/testtemplate
{
   "testtemplate": {
      "order": 0,
      "template": "testsites-*",
      "settings": {},
      "mappings": {
         "type1": {
            "properties": {
               "testurl": {
                  "index": "not_analyzed",
                  "type": "string"
               }
            }
         }
      },
      "aliases": {}
   }
}

```

```auto
POST /testsites-123/type1/
{
  "testurl": "http://localhost/foo/bar"
}

```

```auto
GET /testsites-123/_search
{
  size: 0,
  "aggs": {
    "url_terms": {
      "terms": {
        "field": "testurl"
      }
    }
  }
}

```

The result is:

```auto
   "aggregations": {
      "url_terms": {
         "doc_count_error_upper_bound": 0,
         "sum_other_doc_count": 0,
         "buckets": [
            {
               "key": "http://localhost/foo/bar",
               "doc_count": 1
            }
         ]
      }

```

---

<div class="post-metadata">

### Author: ![aitchon](https://avatars.discourse-cdn.com/v4/letter/a/2bfe46/32.png) [@aitchon](https://discuss.elastic.co/u/aitchon)
#### Post date: [September 21, 2015, 6:54pm UTC](https://discuss.elastic.co/t/querying-a-not-analyzed-field-returning-analyzed-results/29714/5 "2015-09-21T18:54:45Z")

</div>

Yes, I created the template. Here's what I get when I do a get on the template:

```
GET _template/test_template

    {
       "test_template": {
          "order": 0,
          "template": "testsites-*",
          "settings": {
             "index.number_of_replicas": "1",
             "index.number_of_shards": "3"
          },
          "mappings": {
             "site": {
                "properties": {
                   "siteurl": {
                      "index": "not_analyzed",
                      "type": "string"
                   }
                }
             }
          },
          "aliases": {}
       }
    }

```

I ran the same search you gave and still get analyzed terms:

```
GET /testsites-2015-09-21/_search
{
  size: 0,
  "aggs": {
    "url_terms": {
      "terms": {
        "field": "testurl"
      }
    }
  }
}

```

Here's the mapping for the index:

```
{
   "testsites-2015-09-21": {
      "mappings": {
         "site": {
            "properties": {
               "testurl": {
                  "type": "string"
               }
            }
         },
         "boardposts": {
            "properties": {
               "testurl": {
                  "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:48pm UTC](https://discuss.elastic.co/t/querying-a-not-analyzed-field-returning-analyzed-results/29714/6 "2017-07-05T23:48:58Z")

</div>


