# How to check the result of tokenizer after insert one document?

**URL:** <https://discuss.elastic.co/t/how-to-check-the-result-of-tokenizer-after-insert-one-document/57325>\
**Category:** Elasticsearch\
**Created:** [August 5, 2016, 9:14am UTC](https://discuss.elastic.co/t/how-to-check-the-result-of-tokenizer-after-insert-one-document/57325 "2016-08-05T09:14:44Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![WangXiangUSTC](https://avatars.discourse-cdn.com/v4/letter/w/8dc957/32.png) [@WangXiangUSTC](https://discuss.elastic.co/u/WangXiangUSTC)\
**Post date:** [August 5, 2016, 9:14am UTC](https://discuss.elastic.co/t/how-to-check-the-result-of-tokenizer-after-insert-one-document/57325/1 "2016-08-05T09:14:44Z")

</div>

According to my requirement, I custom the analyzer.I know how to check the result using this analyzer, it look like this:  
`curl -XGET "192.168.0.1:9200/test/_analyze?pretty=1&analyzer=pattern_analyzer" -d '2016/08/05 09:57:23 login.go:442: Info: needAAS = true'`

And below is my setting:  
curl -XPUT "192.168.0.1:9200/wangxiang\_test\_5?pretty=1" -d '  
{  
"settings": {  
"analysis": {  
"analyzer": {  
"pattern\_analyzer": {  
"type": "custom",  
"tokenizer": "pattern\_tokenizer"  
}  
},  
"tokenizer": {  
"pattern\_tokenizer": {  
"type": "pattern",  
"pattern": "(\d+:\d+:\d+)|(\d+/\d+/\d+)|\w+",  
"group": "0"  
}  
}  
},  
"mappings": {  
"logs": {  
"properties": {  
"message": {  
"type": "string",  
"analyzer": "pattern\_analyzer"  
}  
}  
}  
}  
}  
}'

And below is how I insert data:

`curl -XPOST "192.168.0.1:9200/test/logs" -d '{"message":"2016/08/05 09:57:23 login.go:442: Info: needAAS = true"}'`

but it seems that my custom analyzer dosen't work when I insert a document to this index. I want to check the token result when insert one document to this index. Is there any API can do this?Or is there any wrong with my setting?

---

<div class="post-metadata">

**Author:** ![cbuescher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbuescher/32/60402_2.png) [@cbuescher](https://discuss.elastic.co/u/cbuescher)\
**Post date:** [August 5, 2016, 9:24am UTC](https://discuss.elastic.co/t/how-to-check-the-result-of-tokenizer-after-insert-one-document/57325/2 "2016-08-05T09:24:36Z")

</div>

Hi,  
You could try and have a look at the term vector for that particular test document using the [\_termvectors API](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-termvectors.html).

---

<div class="post-metadata">

**Author:** ![johtani](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/johtani/32/44956_2.png) [@johtani](https://discuss.elastic.co/u/johtani)\
**Post date:** [August 5, 2016, 11:25am UTC](https://discuss.elastic.co/t/how-to-check-the-result-of-tokenizer-after-insert-one-document/57325/3 "2016-08-05T11:25:25Z")

</div>

You set your custom analyzer to `wangxiang_test_5` index. however you post the data to `test` index.  
You should set the analyzer settings to `test` index or post the data to `wangxiang_test_5`.

---

<div class="post-metadata">

**Author:** ![WangXiangUSTC](https://avatars.discourse-cdn.com/v4/letter/w/8dc957/32.png) [@WangXiangUSTC](https://discuss.elastic.co/u/WangXiangUSTC)\
**Post date:** [August 5, 2016, 11:27am UTC](https://discuss.elastic.co/t/how-to-check-the-result-of-tokenizer-after-insert-one-document/57325/4 "2016-08-05T11:27:23Z")

</div>

I am sorry, I forget to modify this. In fact , I use the same index, but I paste wrong.

---

<div class="post-metadata">

**Author:** ![johtani](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/johtani/32/44956_2.png) [@johtani](https://discuss.elastic.co/u/johtani)\
**Post date:** [August 8, 2016, 3:04am UTC](https://discuss.elastic.co/t/how-to-check-the-result-of-tokenizer-after-insert-one-document/57325/5 "2016-08-08T03:04:03Z")

</div>

Could you show your mappings and settings in you `test` index?  
I copied and pasted your setting in [Sense](https://www.elastic.co/guide/en/sense/current/index.html), then I found 2 errors in your request.  
One is the level of mappings in your request.  
Another one is the `pattern` setting.

The request I posted to Elasticsearch 2.3.4 is here.

```auto
PUT /wangxiang_test_5?pretty=1
{
  "settings": {
    "analysis": {
      "analyzer": {
        "pattern_analyzer": {
          "type": "custom",
          "tokenizer": "pattern_tokenizer"
        }
      },
      "tokenizer": {
        "pattern_tokenizer": {
          "type": "pattern",
          "pattern": "(\\d+:\\d+:\\d+)|(\\d+\\/\\d+\\/\\d+)|\\w+",
          "group": "0"
        }
      }
    }
  },
  "mappings": {
    "logs": {
      "properties": {
        "message": {
          "type": "string",
          "analyzer": "pattern_analyzer"
        }
      }
    }
  }
}

GET /wangxiang_test_5/_settings

GET /wangxiang_test_5/_analyze?pretty=1&analyzer=pattern_analyzer
{
  "analyzer" : "pattern_analyzer",
  "text" : "2016/08/05 09:57:23 login.go:442: Info: needAAS = true"
}

```

And the response is :

```auto
{
  "tokens": [
    {
      "token": "2016/08/05",
      "start_offset": 0,
      "end_offset": 10,
      "type": "word",
      "position": 0
    },
    {
      "token": "09:57:23",
      "start_offset": 11,
      "end_offset": 19,
      "type": "word",
      "position": 1
    },
    {
      "token": "login",
      "start_offset": 20,
      "end_offset": 25,
      "type": "word",
      "position": 2
    },
    {
      "token": "go",
      "start_offset": 26,
      "end_offset": 28,
      "type": "word",
      "position": 3
    },
    {
      "token": "442",
      "start_offset": 29,
      "end_offset": 32,
      "type": "word",
      "position": 4
    },
    {
      "token": "Info",
      "start_offset": 34,
      "end_offset": 38,
      "type": "word",
      "position": 5
    },
    {
      "token": "needAAS",
      "start_offset": 40,
      "end_offset": 47,
      "type": "word",
      "position": 6
    },
    {
      "token": "true",
      "start_offset": 50,
      "end_offset": 54,
      "type": "word",
      "position": 7
    }
  ]
}

```

---

<div class="post-metadata">

**Author:** ![WangXiangUSTC](https://avatars.discourse-cdn.com/v4/letter/w/8dc957/32.png) [@WangXiangUSTC](https://discuss.elastic.co/u/WangXiangUSTC)\
**Post date:** [August 9, 2016, 2:43am UTC](https://discuss.elastic.co/t/how-to-check-the-result-of-tokenizer-after-insert-one-document/57325/6 "2016-08-09T02:43:28Z")

</div>

yeah, you find my mistake. First, I got the wrong level og mappings, and the second is the pattern, it should be double "" ,but I use only one.

Thanks for your reply.

---

<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, 10:29pm UTC](https://discuss.elastic.co/t/how-to-check-the-result-of-tokenizer-after-insert-one-document/57325/7 "2017-07-05T22:29:12Z")

</div>


