Suppose I have two types in the same index, foo and bar. They both
define a field called title. In foo, it makes sense to use stemming
and stop words, so I use the "analyzer": "snowball" in the mapping for
title. In bar, it is better to just use the whitespace analyzer.
I'd like to be able to search for this field and have the query
analyzed using snowball for foo, and whitespace for bar. It appears
that using a query like
{ "query" : { "text" : { "title" : <...> } } }
won't do this when I search the whole index. I can give an analyzer
explicitly but it will be bad for searching on one of the types.
Is there a way to construct a query and/or schema to do what I want?
Suppose I have two types in the same index, foo and bar. They both
define a field called title. In foo, it makes sense to use stemming
and stop words, so I use the "analyzer": "snowball" in the mapping for
title. In bar, it is better to just use the whitespace analyzer.
I'd like to be able to search for this field and have the query
analyzed using snowball for foo, and whitespace for bar. It appears
that using a query like
{ "query" : { "text" : { "title" : <...> } } }
won't do this when I search the whole index. I can give an analyzer
explicitly but it will be bad for searching on one of the types.
Is there a way to construct a query and/or schema to do what I want?
I think a similar issue came up inhttps://github.com/elasticsearch/elasticsearch/issues/1391,
but I don't know if that change also addresses this situation.
You can specify the field prefixed by the type, something like foo.title and
bar.title, this will make sure to use the respective analyzer (and
automatically filter the query to execute only the relevant type).
So, yea, you can use either bool query with two should clauses, one on
foo.title, and one on bar.title, or a dis max one.
Suppose I have two types in the same index, foo and bar. They both
define a field called title. In foo, it makes sense to use stemming
and stop words, so I use the "analyzer": "snowball" in the mapping for
title. In bar, it is better to just use the whitespace analyzer.
I'd like to be able to search for this field and have the query
analyzed using snowball for foo, and whitespace for bar. It appears
that using a query like
{ "query" : { "text" : { "title" : <...> } } }
won't do this when I search the whole index. I can give an analyzer
explicitly but it will be bad for searching on one of the types.
Is there a way to construct a query and/or schema to do what I want?
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.