# I am currently using the Pattern Analyzer, but I found out that the result is wrong. I don't understand why?

**URL:** <https://discuss.elastic.co/t/i-am-currently-using-the-pattern-analyzer-but-i-found-out-that-the-result-is-wrong-i-dont-understand-why/150409>\
**Category:** Elasticsearch\
**Created:** [September 29, 2018, 5:37am UTC](https://discuss.elastic.co/t/i-am-currently-using-the-pattern-analyzer-but-i-found-out-that-the-result-is-wrong-i-dont-understand-why/150409 "2018-09-29T05:37:37Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zhen\_Zhang](https://avatars.discourse-cdn.com/v4/letter/z/2acd7d/32.png) [@Zhen\_Zhang](https://discuss.elastic.co/u/Zhen_Zhang)\
**Post date:** [September 29, 2018, 5:37am UTC](https://discuss.elastic.co/t/i-am-currently-using-the-pattern-analyzer-but-i-found-out-that-the-result-is-wrong-i-dont-understand-why/150409/1 "2018-09-29T05:37:37Z")

</div>

![1](https://us1.discourse-cdn.com/elastic/original/3X/4/f/4f0ac01c18146df58edf6c0fcfc6ebb14814ee09.png)  
 ![2](https://us1.discourse-cdn.com/elastic/original/3X/7/1/716899c64255b705323883f9d9dbd121449fd717.png)

 ![3](https://us1.discourse-cdn.com/elastic/original/3X/3/9/39766d8d381f2168e4a4e3c5f77330f08d1cf896.png)

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 29, 2018, 6:33am UTC](https://discuss.elastic.co/t/i-am-currently-using-the-pattern-analyzer-but-i-found-out-that-the-result-is-wrong-i-dont-understand-why/150409/2 "2018-09-29T06:33:23Z")

</div>

Please don't post images of text as they are hardly readable and not searchable.

Instead paste the text and format it with `</>` icon. Check the preview window.

---

<div class="post-metadata">

**Author:** ![Zhen\_Zhang](https://avatars.discourse-cdn.com/v4/letter/z/2acd7d/32.png) [@Zhen\_Zhang](https://discuss.elastic.co/u/Zhen_Zhang)\
**Post date:** [September 29, 2018, 6:44am UTC](https://discuss.elastic.co/t/i-am-currently-using-the-pattern-analyzer-but-i-found-out-that-the-result-is-wrong-i-dont-understand-why/150409/3 "2018-09-29T06:44:21Z")

</div>

```
{
      "settings": {
        "number_of_replicas": 0,
        "analysis": {
          "analyzer": {
            "douhao": {
              "pattern": ",",
              "type": "pattern"
            },
            "merit_pro_code": {
              "type": "pattern",
              "pattern": "(\\w+)_",
              "lowercase": true
            },
            "merit_pro_time": {
              "type": "pattern",
              "pattern": "\\w+(?<=_)",
              "lowercase": true
            }
          }
        }
      },
      "mappings": {
        "product_info": {
          "properties": {
            "cust_id": {
              "type": "string"
            },
            "pro": {
              "type": "string",
              "analyzer": "douhao",
              "fields": {
                "code": {
                  "type": "string",
                  "analyzer": "merit_pro_code"
                },
                "time": {
                  "type": "string",
                  "analyzer": "merit_pro_time"
                }
              }
            }
          }
        }
      }
    }
```

---

<div class="post-metadata">

**Author:** ![Zhen\_Zhang](https://avatars.discourse-cdn.com/v4/letter/z/2acd7d/32.png) [@Zhen\_Zhang](https://discuss.elastic.co/u/Zhen_Zhang)\
**Post date:** [September 29, 2018, 6:50am UTC](https://discuss.elastic.co/t/i-am-currently-using-the-pattern-analyzer-but-i-found-out-that-the-result-is-wrong-i-dont-understand-why/150409/4 "2018-09-29T06:50:19Z")

</div>

Ok, thank you for your reminder.

---

<div class="post-metadata">

**Author:** ![Zhen\_Zhang](https://avatars.discourse-cdn.com/v4/letter/z/2acd7d/32.png) [@Zhen\_Zhang](https://discuss.elastic.co/u/Zhen_Zhang)\
**Post date:** [September 29, 2018, 6:51am UTC](https://discuss.elastic.co/t/i-am-currently-using-the-pattern-analyzer-but-i-found-out-that-the-result-is-wrong-i-dont-understand-why/150409/5 "2018-09-29T06:51:27Z")

</div>

```
{
  "query": {
    "bool": {
      "must": [
        {
          "prefix": {
            "pro": "b"
          }
        },
        {
          "range": {
            "pro.time": {
              "gte": "20180301",
              "lte": "20180301"
            }
          }
        }
      ]
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 29, 2018, 7:07am UTC](https://discuss.elastic.co/t/i-am-currently-using-the-pattern-analyzer-but-i-found-out-that-the-result-is-wrong-i-dont-understand-why/150409/6 "2018-09-29T07:07:56Z")

</div>

So what is wrong?

Could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

---

<div class="post-metadata">

**Author:** ![Zhen\_Zhang](https://avatars.discourse-cdn.com/v4/letter/z/2acd7d/32.png) [@Zhen\_Zhang](https://discuss.elastic.co/u/Zhen_Zhang)\
**Post date:** [September 29, 2018, 7:15am UTC](https://discuss.elastic.co/t/i-am-currently-using-the-pattern-analyzer-but-i-found-out-that-the-result-is-wrong-i-dont-understand-why/150409/7 "2018-09-29T07:15:51Z")

</div>

I want to view the data containing the b product, and the time range is on the day of March 1st, and the result of this product b is April.

---

<div class="post-metadata">

**Author:** ![Zhen\_Zhang](https://avatars.discourse-cdn.com/v4/letter/z/2acd7d/32.png) [@Zhen\_Zhang](https://discuss.elastic.co/u/Zhen_Zhang)\
**Post date:** [September 29, 2018, 7:21am UTC](https://discuss.elastic.co/t/i-am-currently-using-the-pattern-analyzer-but-i-found-out-that-the-result-is-wrong-i-dont-understand-why/150409/8 "2018-09-29T07:21:31Z")

</div>

The version of elasticsearch used in our project is 2.3.4,  
Why are the following screening results 2 instead of 3?  
Below is my complete query statement

```
{
  "query": {
    "bool": {
      "must": [
        {
          "prefix": {
            "pro": "b"
          }
        },
        {
          "range": {
            "pro.time": {
              "gte": "20180201",
              "lte": "20180201"
            }
          }
        }
      ]
    }
  }
}

```

index info

```
{
  "settings": {
    "number_of_replicas": 0,
    "analysis": {
      "analyzer": {
        "douhao": {
          "pattern": ",",
          "type": "pattern"
        },
        "merit_pro_code": {
          "type": "pattern",
          "pattern": "(\\w+)_",
          "lowercase": true
        },
        "merit_pro_time": {
          "type": "pattern",
          "pattern": "\\w+(?<=_)",
          "lowercase": true
        }
      }
    }
  },
  "mappings": {
    "product_info": {
      "properties": {
        "cust_id": {
          "type": "string"
        },
        "pro": {
          "type": "string",
          "analyzer": "douhao",
          "fields": {
            "code": {
              "type": "string",
              "analyzer": "merit_pro_code"
            },
            "time": {
              "type": "string",
              "analyzer": "merit_pro_time"
            }
          }
        }
      }
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 29, 2018, 7:50am UTC](https://discuss.elastic.co/t/i-am-currently-using-the-pattern-analyzer-but-i-found-out-that-the-result-is-wrong-i-dont-understand-why/150409/9 "2018-09-29T07:50:05Z")

</div>

Please don't post images of text as they are hardly readable and not searchable.

Instead paste the text and format it with `</>` icon. Check the preview window. Please update your post.

Again, provide a full recreation script as described before. And update your version to latest when 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:** [October 27, 2018, 7:59am UTC](https://discuss.elastic.co/t/i-am-currently-using-the-pattern-analyzer-but-i-found-out-that-the-result-is-wrong-i-dont-understand-why/150409/10 "2018-10-27T07:59:54Z")

</div>

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