# How to query the stored, un-analyzed, form of an analyzed field?

**URL:** <https://discuss.elastic.co/t/how-to-query-the-stored-un-analyzed-form-of-an-analyzed-field/13334>\
**Category:** Elasticsearch\
**Created:** [August 26, 2013, 9:28pm UTC](https://discuss.elastic.co/t/how-to-query-the-stored-un-analyzed-form-of-an-analyzed-field/13334 "2013-08-26T21:28:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_5](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chris_5/32/1763_2.png) [@Chris\_5](https://discuss.elastic.co/u/Chris_5)\
**Post date:** [August 26, 2013, 9:28pm UTC](https://discuss.elastic.co/t/how-to-query-the-stored-un-analyzed-form-of-an-analyzed-field/13334/1 "2013-08-26T21:28:04Z")

</div>

I'm having trouble figuring out how the query (search) the 'stored' form of  
a field that has an analyzer. I need to be able to search for both the  
unmodified words, and the synonym mapping I've created at different times.

Take, for example, the following:

{  
"settings" : {  
"analysis" : {  
"analyzer" : {  
"name\_synonym" : {  
"type" : "custom",  
"tokenizer" : "whitespace",  
"filter" : ["lowercase", "name\_synonym"]  
}  
},  
"filter" : {  
"name\_synonym" : {  
"type" : "synonym",  
"synonyms\_path" : "analysis/name\_synonyms.txt"  
}  
}  
}  
},

"mappings" : {  
"record" : {  
"properties" : {  
"name" : { "type" : "string", "analyzer" : "name\_synonym",  
"store" : "yes" }  
}  
}  
}

}

What would I use in my query to indicate that it should only query the  
stored form, and not the analyzed form? That is to say in this example, I  
sometimes want to query for "Chris," and have "Kris," match (works in a  
normal field query with the analyzer in-place), but other times I only want  
to match "Chris" (doesn't work with the analyzer in place).

The current, relevant section of my query looks like this, which searches  
the analyzed form.

{  
'fquery' =\> {  
'\_name' =\> 'recordName',  
'query' =\> {  
'field' =\> {  
'name' =\> 'chris'  
}  
}  
}  
}

Any advice would be greatly appreciated!

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Rafal\_Kuc\_3](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rafal_kuc_3/32/799_2.png) [@Rafal\_Kuc\_3](https://discuss.elastic.co/u/Rafal_Kuc_3)\
**Post date:** [August 26, 2013, 9:32pm UTC](https://discuss.elastic.co/t/how-to-query-the-stored-un-analyzed-form-of-an-analyzed-field/13334/2 "2013-08-26T21:32:38Z")

</div>

Hello!

You can create a multifield ([http://www.elasticsearch.org/guide/reference/mapping/multi-field-type/](http://www.elasticsearch.org/guide/reference/mapping/multi-field-type/)) for the name field which would have two fields. It would look something like this:

"name" : {

"type" : "multi\_field",

"fields" : {

```
"name" : {"type" : "string", "index" : "analyzed", "analyzer": "name_synonym", "store": "yes"},

"not_analyzed" : {"type" : "string", "index" : "not_analyzed"}

```

}

}

You would query the 'name' field when you want to query the analyzed field and you would use the 'name.not\_analyzed' name when you would like to query the non-analyzed form of the field.

Hope that helps.

_--_

Regards,

Rafał Kuć

Sematext :: [http://sematext.com/](http://sematext.com/) _:: Solr - Lucene - ElasticSearch_

I'm having trouble figuring out how the query (search) the 'stored' form of a field that has an analyzer. I need to be able to search for both the unmodified words, and the synonym mapping I've created at different times.

Take, for example, the following:

{

"settings" : {

```
"analysis" : {

    "analyzer" : {

        "name_synonym" : {

            "type" : "custom",

            "tokenizer" : "whitespace",

            "filter" : ["lowercase", "name_synonym"]

        }

     },

     "filter" : {

        "name_synonym" : {

            "type" : "synonym",

            "synonyms_path" : "analysis/name_synonyms.txt"

        }

     }

}

```

},

"mappings" : {

```
"record" : {

    "properties" : {

        "name" : { "type" : "string", "analyzer" : "name_synonym", "store" : "yes" }

    }

}

```

}

}

What would I use in my query to indicate that it should only query the stored form, and not the analyzed form? That is to say in this example, I sometimes want to query for "Chris," and have "Kris," match (works in a normal field query with the analyzer in-place), but other times I only want to match "Chris" (doesn't work with the analyzer in place).

The current, relevant section of my query looks like this, which searches the analyzed form.

{

'fquery' =\> {

```
    '_name' =&gt; 'recordName',

    'query' =&gt; {

             'field' =&gt; {

                  'name' =&gt; 'chris'

                }

           }

      }

```

}

Any advice would be greatly appreciated!

--

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).

For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Chris\_5](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chris_5/32/1763_2.png) [@Chris\_5](https://discuss.elastic.co/u/Chris_5)\
**Post date:** [August 26, 2013, 9:40pm UTC](https://discuss.elastic.co/t/how-to-query-the-stored-un-analyzed-form-of-an-analyzed-field/13334/3 "2013-08-26T21:40:22Z")

</div>

On Monday, August 26, 2013 4:32:38 PM UTC-5, Rafał Kuć wrote:

> Hello!
> 
> You can create a multifield (  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/multi-field-type/))  
> for the name field which would have two fields. It would look something  
> like this:

Both are perfect, thanks!

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Chris\_5](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chris_5/32/1763_2.png) [@Chris\_5](https://discuss.elastic.co/u/Chris_5)\
**Post date:** [August 26, 2013, 9:47pm UTC](https://discuss.elastic.co/t/how-to-query-the-stored-un-analyzed-form-of-an-analyzed-field/13334/4 "2013-08-26T21:47:19Z")

</div>

... as a follow-up and side-note, it looks like it -does- have to be  
multifield, as not\_analyzed won't work in this case. I need to use a  
default analyzer as the string still needs to be tokenized. (It's usually  
a whole name, multiple words.) So, multifield appears to be the correct  
solution here!

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:19am UTC](https://discuss.elastic.co/t/how-to-query-the-stored-un-analyzed-form-of-an-analyzed-field/13334/5 "2017-07-06T02:19:42Z")

</div>


