title: Elasticsearch custom analyzer not working
body: <p>I am using elasticsearch as my search engine, I am now trying to create an custom analyzer to make the field value just lowercase. The following is my code:</p>
  
  <p><strong>Create index and mapping</strong></p>
  
  <pre><code>create index with a custom analyzer named test_lowercase：
  
  curl -XPUT 'localhost:9200/test/' -d '{
    "settings": {
      "analysis": {
        "analyzer": {
          "test_lowercase": {
            "type": "pattern",
            "pattern": "^.*$"
          }
        }
      }
    }
  }'
  
  create a mapping using the test_lowercase analyzer for the address field：
  
  curl -XPUT 'localhost:9200/test/_mapping/Users' -d '{
    "Users": {
      "properties": {
        "name": {
          "type": "string"
        },
        "address": {
          "type": "string",
          "analyzer": "test_lowercase"
        }
      }
    }
  }'
  </code></pre>
  
  <p><strong>To verify if the test_lowercase analyzer work:</strong></p>
  
  <pre><code>curl -XGET 'localhost:9200/test/_analyze?analyzer=test_lowercase&amp;pretty' -d '
  Beijing China
  '
  {
    "tokens" : [ {
      "token" : "\nbeijing china\n",
      "start_offset" : 0,
      "end_offset" : 15,
      "type" : "word",
      "position" : 0
    } ]
  }
  </code></pre>
  
  <p>As we can see, the string 'Beijing China' is indexed as a single lowercase-ed whole term 'beijing china', so the test_lowercase analyzer works fine. </p>
  
  <p><strong>To verify if the field 'address' is using the lowercase analyzer:</strong></p>
  
  <pre><code>curl -XGET 'http://localhost:9200/test/_analyze?field=address&amp;pretty' -d '
  Beijing China
  '
  {
    "tokens" : [ {
      "token" : "\nbeijing china\n",
      "start_offset" : 0,
      "end_offset" : 15,
      "type" : "word",
      "position" : 0
    } ]
  }
  curl -XGET 'http://localhost:9200/test/_analyze?field=name&amp;pretty' -d '
  Beijing China
  '
  {
    "tokens" : [ {
      "token" : "beijing",
      "start_offset" : 1,
      "end_offset" : 8,
      "type" : "&lt;ALPHANUM&gt;",
      "position" : 0
    }, {
      "token" : "china",
      "start_offset" : 9,
      "end_offset" : 14,
      "type" : "&lt;ALPHANUM&gt;",
      "position" : 1
    } ]
  }
  </code></pre>
  
  <p>As we can see, for the same string 'Beijing China', if we use field=address to analyze, it creates a single item 'beijing china', when using field=name, we got two items 'beijing' and 'china', so it seems the field address is using my custom analyzer 'test_lowercase'.</p>
  
  <p><strong>Insert a document to the test index to see if the analyzer works for documents</strong></p>
  
  <pre><code>curl -XPUT 'localhost:9200/test/Users/12345?pretty' -d '{"name": "Jinshui Tang",  "address": "Beijing China"}'
  </code></pre>
  
  <p>Unfortunately, the document has been successfully inserted but the address field has not been correctly analyzed. I can't search out it by using the wildcard query as follows:</p>
  
  <pre><code>curl -XGET 'http://localhost:9200/test/Users/_search?pretty' -d '
  {
    "query": {
      "wildcard": {
        "address": "*beijing ch*"
      }
    }
  }'
  {
    "took" : 8,
    "timed_out" : false,
    "_shards" : {
      "total" : 5,
      "successful" : 5,
      "failed" : 0
    },
    "hits" : {
      "total" : 0,
      "max_score" : null,
      "hits" : [ ]
    }
  }
  </code></pre>
  
  <p><strong>List all terms analyzed for the document:</strong></p>
  
  <p>So I run the following commands to see all terms of the document, and I found that the 'Beijing China' is not in the term vector at all.</p>
  
  <pre><code>curl -XGET 'http://localhost:9200/test/Users/12345/_termvector?fields=*&amp;pretty'
  {
    "_index" : "test",
    "_type" : "Users",
    "_id" : "12345",
    "_version" : 3,
    "found" : true,
    "took" : 2,
    "term_vectors" : {
      "name" : {
        "field_statistics" : {
          "sum_doc_freq" : 2,
          "doc_count" : 1,
          "sum_ttf" : 2
        },
        "terms" : {
          "jinshui" : {
            "term_freq" : 1,
            "tokens" : [ {
              "position" : 0,
              "start_offset" : 0,
              "end_offset" : 7
            } ]
          },
          "tang" : {
            "term_freq" : 1,
            "tokens" : [ {
              "position" : 1,
              "start_offset" : 8,
              "end_offset" : 12
            } ]
          }
        }
      }
    }
  }
  </code></pre>
  
  <p>We can see that the name is correctly analyzed and it became two terms 'jinshui' and 'tang', but the address is lost. </p>
  
  <p>Can anyone please help? Is there anything missing?</p>
  
  <p>Thanks a lot!</p>