# How Percolate can perform, qeries on not analyzed index?

**URL:** https://discuss.elastic.co/t/how-percolate-can-perform-qeries-on-not-analyzed-index/103098
**Category:** Elasticsearch
**Created:** [October 7, 2017, 3:08am UTC](https://discuss.elastic.co/t/how-percolate-can-perform-qeries-on-not-analyzed-index/103098 "2017-10-07T03:08:45Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![sarath\_r\_nair](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sarath_r_nair/32/61664_2.png) [@sarath\_r\_nair](https://discuss.elastic.co/u/sarath_r_nair)
#### Post date: [October 7, 2017, 3:08am UTC](https://discuss.elastic.co/t/how-percolate-can-perform-qeries-on-not-analyzed-index/103098/1 "2017-10-07T03:08:45Z")

</div>

So , after so much of digging around , I came to ask it over here . Let me start with a simple use case .

```
curl -XPUT 'localhost:9200/my-index?pretty' -H 'Content-Type: application/json' -d'
{
    "mappings": {
        "doctype": {
            "properties": {
                "message": {
                    "type": "text" }
            }
        },
        "queries": {
            "properties": {
                "query": {
                    "type": "percolator"
                }
            }
        }
    }
}
'

curl -XPUT 'localhost:9200/my-index/queries/2?refresh&pretty' -H 'Content-Type: application/json' -d'
{
    "query" : {
        "match_phrase" : {
            "message" : "pub/sub"
        }
    }
}
'

curl -XPUT 'localhost:9200/my-index/queries/1?refresh&pretty' -H 'Content-Type: application/json' -d'
{
    "query" : {
        "match_phrase" : {
            "message" : "x++"
        }
    }
}
'

```

Now my problem is if I execute

```
curl -XGET 'localhost:9200/my-index/_search?pretty' -H 'Content-Type: application/json' -d'
{
    "query" : {
        "percolate" : {
            "field" : "query",
            "document_type" : "doctype",
            "document" : {
                "message" : "A new bonsai pub sub tree in the office x"
            }
        }
    }
}
'

```

I will get two matched . one for "pub" and other for "x" , as pub'/sub and x++ .. I know , its because of analyzer . But , even in the mapping field if I change to

```
curl -XPUT 'localhost:9200/my-index?pretty' -H 'Content-Type: application/json' -d'
{
"mappings": {
    "doctype": {
        "properties": {
            "message": {
                "type": "string" , 
                "index": "not_analyzed" }
        }
    },
    "queries": {
        "properties": {
            "query": {
                "type": "percolator"
            }
        }
    }
}
}
'

```

then the "message" : "A new bonsai pub sub tree in the office x" will give zero match , because , it passes this entire text / doc as not\_analyzed .

In simple any way to solve this issue ? I only want those phrase . non phrase queries to be matched , which are indexed without removing any special charaxcters like / , + etc ?

---

<div class="post-metadata">

### Author: ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)
#### Post date: [October 7, 2017, 4:42am UTC](https://discuss.elastic.co/t/how-percolate-can-perform-qeries-on-not-analyzed-index/103098/2 "2017-10-07T04:42:58Z")

</div>

By default, the `text` field uses the `standard` analyzer. If you use the `whitespace` analyzer instead then your input will simply be split on whitespaces (but the token will not be be lowercased)

```
"mappings": {
    "doctype": {
        "properties": {
            "message": {
                "type": "text",
                "analyzer": "whitespace"
            }
        }
    },

```

If you also want the tokens to be lowercased, then you need to create a custom analyzer

```
curl -XPUT 'localhost:9200/my-index?pretty' -H 'Content-Type: application/json' -d'{
  "settings": {
    "analysis": {
      "analyzer": {
        "my_analyzer": {
          "type": "custom",
          "tokenizer": "whitespace",
          "filter": [
            "lowercase"
          ]
        }
      }
    }
  },
  "mappings": {
    "doctype": {
      "properties": {
        "message": {
          "type": "text",
          "analyzer": "my_analyzer"
        }
      }
    },
    "queries": {
      "properties": {
        "query": {
          "type": "percolator"
        }
      }
    }
  }
}'

```

Then this will only match the `pub/sub` query

```
curl -XGET 'localhost:9200/my-index/_search?pretty' -H 'Content-Type: application/json' -d'
    {
        "query" : {
            "percolate" : {
                "field" : "query",
                "document_type" : "doctype",
                "document" : {
                    "message" : "A new bonsai pub/sub tree in the office x"
            }
        }
    }
}
'
```

---

<div class="post-metadata">

### Author: ![sarath\_r\_nair](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sarath_r_nair/32/61664_2.png) [@sarath\_r\_nair](https://discuss.elastic.co/u/sarath_r_nair)
#### Post date: [October 7, 2017, 10:22am UTC](https://discuss.elastic.co/t/how-percolate-can-perform-qeries-on-not-analyzed-index/103098/3 "2017-10-07T10:22:47Z")

</div>

Thank you so much vaal crettaz . Amazing and very precise explanation.

---

<div class="post-metadata">

### Author: ![val](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/val/32/138203_2.png) [@val](https://discuss.elastic.co/u/val)
#### Post date: [October 7, 2017, 11:47am UTC](https://discuss.elastic.co/t/how-percolate-can-perform-qeries-on-not-analyzed-index/103098/4 "2017-10-07T11:47:46Z")

</div>

Awesome, glad it helped 😉

---

<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: [November 4, 2017, 11:48am UTC](https://discuss.elastic.co/t/how-percolate-can-perform-qeries-on-not-analyzed-index/103098/5 "2017-11-04T11:48:27Z")

</div>

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