Question about schemaless support


(Tomasz Kloc) #1

Hello,

I have an application based on mongodb, which uses main feature of nosql

  • no schema at all. This is a common 'classified ads' application with
    collections of ads and categories. I didn't want to use EAV model, so
    i've chosen MongoDB. If category has some custom fields (ie. RAM for
    category Computers) I simple add this field to Ad record.
    Now I want to implement elasticsearch for search purposes and facet
    searches. I'm using Python & pyes library.
    Pyes documentation says that i have to:
  1. create a connection (conn = pyes.ES() )
  2. create an index ( conn.create_index("test-index") )
  3. put some document type (mapping)

Is this required? Document has dynamic fields and can look like
{"id": ..., "title": ..., "price": ..., "ram": ... } for Computers
or
{"id": ..., "title": ..., "price": ..., "color": ...} for Cars

My questions are:

  • do i have to create mapping for document?
  • can i index these custom fields?
  • can i search for objects with custom fields as filters?
  • can i apply 'facets' to searches/queries described above?

or should i create mappings for each category with custom fields?

tk


(Shay Banon) #2

On Mon, Oct 31, 2011 at 4:59 PM, Tomasz Kloc tomek.kloc.iit@gmail.comwrote:

Hello,

I have an application based on mongodb, which uses main feature of nosql -
no schema at all. This is a common 'classified ads' application with
collections of ads and categories. I didn't want to use EAV model, so i've
chosen MongoDB. If category has some custom fields (ie. RAM for category
Computers) I simple add this field to Ad record.
Now I want to implement elasticsearch for search purposes and facet
searches. I'm using Python & pyes library.
Pyes documentation says that i have to:
0) create a connection (conn = pyes.ES() )

  1. create an index ( conn.create_index("test-index"**) )
  2. put some document type (mapping)

Is this required? Document has dynamic fields and can look like
{"id": ..., "title": ..., "price": ..., "ram": ... } for Computers
or
{"id": ..., "title": ..., "price": ..., "color": ...} for Cars

My questions are:

  • do i have to create mapping for document?

You don't have to create mapping for those fields. The types for them will
be automatically detected based on the first document indexed, and used. If
you want to control the mappings, then you need to create mappings, but
only for the fields you want to control.

  • can i index these custom fields?

Sure.

  • can i search for objects with custom fields as filters?

The fields are available for search in any form you want.

  • can i apply 'facets' to searches/queries described above?

Yes. Though note, sometimes you would want to make a field "not analyzed"
for better facet results (so it won't be broken down into terms).

or should i create mappings for each category with custom fields?

tk


(system) #3