Searching across types


(James Cook) #1

When performing a search across multiple types, is is possible to indicate
the fields that should be searched on a per-type basis?


(Shay Banon) #2

Let me explain a bit how types work in elasticsearch. At the end of the day,
Lucene index has Documents and has no notion of types. Types are something
added (as best as possible) by elasticsearch. A lucene document is a flat
structure key value pair (so objects in json are also translated to this),
and a type ends up as another field within the document (called _type).

Then you build a query and in the field (any query that acces a field to
execute on), you can specify type1.field1, and in this case, it will be
automatically detected, and the query will be wrapped to only be executed
match on docs with _type:type1 (in an efficient manner), on field1.

This does mean that across types, having the same field name with different
mappings types (for example, type1 has field1 of type numeric, and type2
also has field1 but of type string) should not be done (working on
automatically detecting that...).

So, the type prefix when you define the field name should allow to only
search on a field against that specific type. (At the end of the day, it is
wrapped in a filtered query with a _type:type1 term filter).

-shay.banon

On Thu, Oct 21, 2010 at 2:55 PM, James Cook jcook@tracermedia.com wrote:

When performing a search across multiple types, is is possible to indicate
the fields that should be searched on a per-type basis?


(James Cook) #3

That's such good information, and makes it much clearer for me. Thank you.

On Thu, Oct 21, 2010 at 5:44 PM, Shay Banon shay.banon@elasticsearch.comwrote:

Let me explain a bit how types work in elasticsearch. At the end of the
day, Lucene index has Documents and has no notion of types. Types are
something added (as best as possible) by elasticsearch. A lucene document is
a flat structure key value pair (so objects in json are also translated to
this), and a type ends up as another field within the document (called
_type).

Then you build a query and in the field (any query that acces a field to
execute on), you can specify type1.field1, and in this case, it will be
automatically detected, and the query will be wrapped to only be executed
match on docs with _type:type1 (in an efficient manner), on field1.

This does mean that across types, having the same field name with different
mappings types (for example, type1 has field1 of type numeric, and type2
also has field1 but of type string) should not be done (working on
automatically detecting that...).

So, the type prefix when you define the field name should allow to only
search on a field against that specific type. (At the end of the day, it is
wrapped in a filtered query with a _type:type1 term filter).

-shay.banon

On Thu, Oct 21, 2010 at 2:55 PM, James Cook jcook@tracermedia.com wrote:

When performing a search across multiple types, is is possible to indicate
the fields that should be searched on a per-type basis?


(system) #4