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

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.
For more options, visit https://groups.google.com/groups/opt_out.

Hello!

You can create a multifield (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/ :: 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' => '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.

For more options, visit https://groups.google.com/groups/opt_out.

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)
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.
For more options, visit https://groups.google.com/groups/opt_out.

... 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.
For more options, visit https://groups.google.com/groups/opt_out.