# How I can do exact search by "not\_analyzed" fields?

**URL:** <https://discuss.elastic.co/t/how-i-can-do-exact-search-by-not-analyzed-fields/18954>\
**Category:** Elasticsearch\
**Created:** [July 29, 2014, 5:28pm UTC](https://discuss.elastic.co/t/how-i-can-do-exact-search-by-not-analyzed-fields/18954 "2014-07-29T17:28:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexey\_Sidelnikov](https://avatars.discourse-cdn.com/v4/letter/a/c5a1d2/32.png) [@Alexey\_Sidelnikov](https://discuss.elastic.co/u/Alexey_Sidelnikov)\
**Post date:** [July 29, 2014, 5:28pm UTC](https://discuss.elastic.co/t/how-i-can-do-exact-search-by-not-analyzed-fields/18954/1 "2014-07-29T17:28:20Z")

</div>

Hi all!

Tired to find out the decision. I have some fields in my index that are  
not\_analized. Suppose something like that in mappings:{  
"test-index-entities": {  
"mappings": {  
"testobject": {  
"properties": {  
"\_\_location": {  
"type": "geo\_point"  
},  
"activity\_end": {  
"type": "long"  
},  
"activity\_start": {  
"type": "long"  
},  
"attributes": {},  
"createdBy": {  
"type": "string",  
"index": "not\_analyzed",  
"include\_in\_all": true  
}  
}  
}  
}  
}  
}

Suppose I have value of "createdBy" attribute equals to "John Smith", and I  
want to query ALL documents that have ANY field equals to "John Smith". As  
I have field "createdBy" as not\_analyzed, I should have one term "John  
Smith" in \_all field.

But executing of match query:  
{  
"match" : {  
"\_all" : "John Smith"  
}  
}

don't give results. I think that is because match query tokenizes query  
itself and search for "john" and "smith" terms instead of searching by  
not\_tokenized "John Smith". In case of  
{  
"match" : {  
"createdBy" : "John Smith"  
}  
}  
all works fine, as ES finds in mappings that field is not tokenized.

Is there any way to specify in match query not to analyze query string? I  
see "analyzer" parameter in documentation  
[http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-match-query.html](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-match-query.html),  
tried "analyzer" : "none", "analyzer" : "not\_analyzed", but it doesn't work.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/c1d9ca4f-a0d3-4a50-a6a5-e3a59f972f5c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c1d9ca4f-a0d3-4a50-a6a5-e3a59f972f5c%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [July 29, 2014, 5:52pm UTC](https://discuss.elastic.co/t/how-i-can-do-exact-search-by-not-analyzed-fields/18954/2 "2014-07-29T17:52:17Z")

</div>

The \_all field has its own analyzer, so the analyzer that is defined on the  
createdBy field is not applied.

I have never tried, but I believe the best solution is to use "copy-to" to  
a custom field:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

It should copy the tokens post-analysis.

Cheers,

Ivan

On Tue, Jul 29, 2014 at 10:28 AM, Alexey Sidelnikov \<  
[alexey.sidelnikov@reltio.com](mailto:alexey.sidelnikov@reltio.com)\> wrote:

> Hi all!
> 
> Tired to find out the decision. I have some fields in my index that are  
> not\_analized. Suppose something like that in mappings:{  
> "test-index-entities": {  
> "mappings": {  
> "testobject": {  
> "properties": {  
> "\_\_location": {  
> "type": "geo\_point"  
> },  
> "activity\_end": {  
> "type": "long"  
> },  
> "activity\_start": {  
> "type": "long"  
> },  
> "attributes": {},  
> "createdBy": {  
> "type": "string",  
> "index": "not\_analyzed",  
> "include\_in\_all": true  
> }  
> }  
> }  
> }  
> }  
> }
> 
> Suppose I have value of "createdBy" attribute equals to "John Smith", and  
> I want to query ALL documents that have ANY field equals to "John Smith".  
> As I have field "createdBy" as not\_analyzed, I should have one term "John  
> Smith" in \_all field.
> 
> But executing of match query:  
> {  
> "match" : {  
> "\_all" : "John Smith"  
> }  
> }
> 
> don't give results. I think that is because match query tokenizes query  
> itself and search for "john" and "smith" terms instead of searching by  
> not\_tokenized "John Smith". In case of  
> {  
> "match" : {  
> "createdBy" : "John Smith"  
> }  
> }  
> all works fine, as ES finds in mappings that field is not tokenized.
> 
> Is there any way to specify in match query not to analyze query string? I  
> see "analyzer" parameter in documentation  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-match-query.html),  
> tried "analyzer" : "none", "analyzer" : "not\_analyzed", but it doesn't work.
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/c1d9ca4f-a0d3-4a50-a6a5-e3a59f972f5c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c1d9ca4f-a0d3-4a50-a6a5-e3a59f972f5c%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/c1d9ca4f-a0d3-4a50-a6a5-e3a59f972f5c%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/c1d9ca4f-a0d3-4a50-a6a5-e3a59f972f5c%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQD2nBVB%2Bdktqr8coLWzXCzqLhc8bcmJisaJ%2Bo2q\_-M\_rQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQD2nBVB%2Bdktqr8coLWzXCzqLhc8bcmJisaJ%2Bo2q_-M_rQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [July 29, 2014, 5:55pm UTC](https://discuss.elastic.co/t/how-i-can-do-exact-search-by-not-analyzed-fields/18954/3 "2014-07-29T17:55:16Z")

</div>

If I actually read the documentation I provided, I would have seen that my  
assumption is wrong. 🙂 copy-to fields also define their own analyzer and  
do not use post-analysis tokens.

Not sure if there is a clean way to achieve this goal in Elasticsearch. I  
handle the use case by custom logic on the client side. My application  
knows which fields are analyzed and which are not and creates queries  
accordingly.

--  
Ivan

On Tue, Jul 29, 2014 at 10:52 AM, Ivan Brusic [ivan@brusic.com](mailto:ivan@brusic.com) wrote:

> The \_all field has its own analyzer, so the analyzer that is defined on  
> the createdBy field is not applied.
> 
> I have never tried, but I believe the best solution is to use "copy-to" to  
> a custom field:
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-core-types.html#copy-to)
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/custom-all.html)
> 
> It should copy the tokens post-analysis.
> 
> Cheers,
> 
> Ivan
> 
> On Tue, Jul 29, 2014 at 10:28 AM, Alexey Sidelnikov \<  
> [alexey.sidelnikov@reltio.com](mailto:alexey.sidelnikov@reltio.com)\> wrote:
> 
> > Hi all!
> > 
> > Tired to find out the decision. I have some fields in my index that are  
> > not\_analized. Suppose something like that in mappings:{  
> > "test-index-entities": {  
> > "mappings": {  
> > "testobject": {  
> > "properties": {  
> > "\_\_location": {  
> > "type": "geo\_point"  
> > },  
> > "activity\_end": {  
> > "type": "long"  
> > },  
> > "activity\_start": {  
> > "type": "long"  
> > },  
> > "attributes": {},  
> > "createdBy": {  
> > "type": "string",  
> > "index": "not\_analyzed",  
> > "include\_in\_all": true  
> > }  
> > }  
> > }  
> > }  
> > }  
> > }
> > 
> > Suppose I have value of "createdBy" attribute equals to "John Smith", and  
> > I want to query ALL documents that have ANY field equals to "John Smith".  
> > As I have field "createdBy" as not\_analyzed, I should have one term "John  
> > Smith" in \_all field.
> > 
> > But executing of match query:  
> > {  
> > "match" : {  
> > "\_all" : "John Smith"  
> > }  
> > }
> > 
> > don't give results. I think that is because match query tokenizes query  
> > itself and search for "john" and "smith" terms instead of searching by  
> > not\_tokenized "John Smith". In case of  
> > {  
> > "match" : {  
> > "createdBy" : "John Smith"  
> > }  
> > }  
> > all works fine, as ES finds in mappings that field is not tokenized.
> > 
> > Is there any way to specify in match query not to analyze query string? I  
> > see "analyzer" parameter in documentation  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-match-query.html),  
> > tried "analyzer" : "none", "analyzer" : "not\_analyzed", but it doesn't work.
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/c1d9ca4f-a0d3-4a50-a6a5-e3a59f972f5c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c1d9ca4f-a0d3-4a50-a6a5-e3a59f972f5c%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/c1d9ca4f-a0d3-4a50-a6a5-e3a59f972f5c%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/c1d9ca4f-a0d3-4a50-a6a5-e3a59f972f5c%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQD4MP7wVF0n%2Boi3Sz\_2FaPohQjwDRbU4oYgei4s6WHPPg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQD4MP7wVF0n%2Boi3Sz_2FaPohQjwDRbU4oYgei4s6WHPPg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Alexey\_Sidelnikov](https://avatars.discourse-cdn.com/v4/letter/a/c5a1d2/32.png) [@Alexey\_Sidelnikov](https://discuss.elastic.co/u/Alexey_Sidelnikov)\
**Post date:** [July 29, 2014, 6:13pm UTC](https://discuss.elastic.co/t/how-i-can-do-exact-search-by-not-analyzed-fields/18954/4 "2014-07-29T18:13:27Z")

</div>

Thank you for reply.

Really I want to search by all document fields and enumerating all possible  
attribute values in bool query is not good idea for me as my documents have  
large number of different attribute names.

Idea we used before, we didn't used not\_analyzed, but used our own encoder  
to encode field values to some string without token delimiters. But we  
think that it is not good way to do this, we want to try to find out  
Elasticsearch solution as really ES holds not\_analyzed values as terms, and  
it should be the fastest query I can imagine for ES - "find all documents  
having term like 'John Smith'"

Surely we can create our own \_all filed instead of out of the box, like  
"allnottokenized" that would contain all non\_analyzed values that document  
have in all not\_analyzed attributes. But it is huge work - every time when  
indexing document, we need to check mapping for every attribute to  
understand whether it tokenzied or not and then fill our own all value.  
Strange if ES doesn't have such simple functionality out of the box

On Tuesday, July 29, 2014 9:55:24 PM UTC+4, Ivan Brusic wrote:

> If I actually read the documentation I provided, I would have seen that my  
> assumption is wrong. 🙂 copy-to fields also define their own analyzer and  
> do not use post-analysis tokens.
> 
> Not sure if there is a clean way to achieve this goal in Elasticsearch. I  
> handle the use case by custom logic on the client side. My application  
> knows which fields are analyzed and which are not and creates queries  
> accordingly.
> 
> --  
> Ivan
> 
> On Tue, Jul 29, 2014 at 10:52 AM, Ivan Brusic \<[iv...@brusic.com](mailto:iv...@brusic.com)  
> \<javascript:\>\> wrote:
> 
> > The \_all field has its own analyzer, so the analyzer that is defined on  
> > the createdBy field is not applied.
> > 
> > I have never tried, but I believe the best solution is to use "copy-to"  
> > to a custom field:
> > 
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-core-types.html#copy-to)
> > 
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/custom-all.html)
> > 
> > It should copy the tokens post-analysis.
> > 
> > Cheers,
> > 
> > Ivan
> > 
> > On Tue, Jul 29, 2014 at 10:28 AM, Alexey Sidelnikov \<  
> > [alexey.s...@reltio.com](mailto:alexey.s...@reltio.com) \<javascript:\>\> wrote:
> > 
> > > Hi all!
> > > 
> > > Tired to find out the decision. I have some fields in my index that are  
> > > not\_analized. Suppose something like that in mappings:{  
> > > "test-index-entities": {  
> > > "mappings": {  
> > > "testobject": {  
> > > "properties": {  
> > > "\_\_location": {  
> > > "type": "geo\_point"  
> > > },  
> > > "activity\_end": {  
> > > "type": "long"  
> > > },  
> > > "activity\_start": {  
> > > "type": "long"  
> > > },  
> > > "attributes": {},  
> > > "createdBy": {  
> > > "type": "string",  
> > > "index": "not\_analyzed",  
> > > "include\_in\_all": true  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }
> > > 
> > > Suppose I have value of "createdBy" attribute equals to "John Smith",  
> > > and I want to query ALL documents that have ANY field equals to "John  
> > > Smith". As I have field "createdBy" as not\_analyzed, I should have one term  
> > > "John Smith" in \_all field.
> > > 
> > > But executing of match query:  
> > > {  
> > > "match" : {  
> > > "\_all" : "John Smith"  
> > > }  
> > > }
> > > 
> > > don't give results. I think that is because match query tokenizes query  
> > > itself and search for "john" and "smith" terms instead of searching by  
> > > not\_tokenized "John Smith". In case of  
> > > {  
> > > "match" : {  
> > > "createdBy" : "John Smith"  
> > > }  
> > > }  
> > > all works fine, as ES finds in mappings that field is not tokenized.
> > > 
> > > Is there any way to specify in match query not to analyze query string?  
> > > I see "analyzer" parameter in documentation  
> > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-match-query.html),  
> > > tried "analyzer" : "none", "analyzer" : "not\_analyzed", but it doesn't work.
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google  
> > > Groups "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send  
> > > an email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > > To view this discussion on the web visit  
> > > [https://groups.google.com/d/msgid/elasticsearch/c1d9ca4f-a0d3-4a50-a6a5-e3a59f972f5c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c1d9ca4f-a0d3-4a50-a6a5-e3a59f972f5c%40googlegroups.com)  
> > > [https://groups.google.com/d/msgid/elasticsearch/c1d9ca4f-a0d3-4a50-a6a5-e3a59f972f5c%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/c1d9ca4f-a0d3-4a50-a6a5-e3a59f972f5c%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > > .  
> > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/43e411f6-0c85-460e-b7ee-65261f2eec83%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/43e411f6-0c85-460e-b7ee-65261f2eec83%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 6, 2017, 1:12am UTC](https://discuss.elastic.co/t/how-i-can-do-exact-search-by-not-analyzed-fields/18954/5 "2017-07-06T01:12:27Z")

</div>


