Search a field using analyzer specific to type

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 in https://github.com/elasticsearch/elasticsearch/issues/1391,
but I don't know if that change also addresses this situation.

I found using a dis_max of the same query under two analyzers achieved
good results. Is this the preferred way to this though?

On Oct 24, 7:43 pm, James Wilson jwilson...@gmail.com wrote:

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.

On Tue, Oct 25, 2011 at 8:24 PM, James Wilson jwilson556@gmail.com wrote:

I found using a dis_max of the same query under two analyzers achieved
good results. Is this the preferred way to this though?

On Oct 24, 7:43 pm, James Wilson jwilson...@gmail.com wrote:

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://
When searching against an index/type, use the type information to derive different search aspects · Issue #1391 · elastic/elasticsearch · GitHub,
but I don't know if that change also addresses this situation.