Simplifying search

Hello,

I am trying to figure out, if there a way to reduce a number of
queries in my search.
I use data model like the following:

Person {
id: ,
name:
}

Location {
id: ,
name:
}

Relation {
personId: ,
locationId: ,
type:
}

Persons and Locations are tied with Relations as many-to-many.
Relations can be of different types (e.g. "home", "work").
The documents are indexed into the same index with different types:
Person, Location, Relation.

My search should find all Persons which are related to a Location with
Location.name = "someLocation",
and Relation.type = "someType".

I can do that by running a number of queries sequentially:

  1. find Location.id by Location.name (termFilter, filteredQuery);
  2. find all matching Relation.personId by Relation.type and
    Relation.locationId (andFilter, filteredQuery);
  3. find all matching Persons by Person.id (termFilter, filteredQuery).

Is it possible to simplify this search somehow, is there a way to do
it in one query?

Thanks,
Anna

Looks like you are trying to apply sql like concepts in a NoSql world.

Not sure I'm right, but I will store Person content and Location content directly in the Relation document. Such as :

Relation {
Person {

name:
},
,Location {
name:
}
type:
}

Then, searches are quite simples to implement.

Make sense ?

HTH
David :wink:

Le 31 août 2011 à 22:18, Anna anna.grigoryeva@googlemail.com a écrit :

Hello,

I am trying to figure out, if there a way to reduce a number of
queries in my search.
I use data model like the following:

Person {
id: ,
name:
}

Location {
id: ,
name:
}

Relation {
personId: ,
locationId: ,
type:
}

Persons and Locations are tied with Relations as many-to-many.
Relations can be of different types (e.g. "home", "work").
The documents are indexed into the same index with different types:
Person, Location, Relation.

My search should find all Persons which are related to a Location with
Location.name = "someLocation",
and Relation.type = "someType".

I can do that by running a number of queries sequentially:

  1. find Location.id by Location.name (termFilter, filteredQuery);
  2. find all matching Relation.personId by Relation.type and
    Relation.locationId (andFilter, filteredQuery);
  3. find all matching Persons by Person.id (termFilter, filteredQuery).

Is it possible to simplify this search somehow, is there a way to do
it in one query?

Thanks,
Anna

This seems like you are trying to use the wrong tool for the job. I assume
this data is originating in a database, why not just use the database to get
the information you want? You are not doing anything that requires a search
engine.

If you still want to try and do this with ES, I would use a different
indexing strategy... maybe index people with their relationships to
locations as a nested object:

person: {
name,
relation: [
{locationName, type},
{locationName, type},
{locationName, type}
]
}

Once you index docs like this you can use nested queries to find all people
with a certain location and type. Good luck.

Thanks,
Matt Weber

On Wed, Aug 31, 2011 at 1:18 PM, Anna anna.grigoryeva@googlemail.comwrote:

Hello,

I am trying to figure out, if there a way to reduce a number of
queries in my search.
I use data model like the following:

Person {
id: ,
name:
}

Location {
id: ,
name:
}

Relation {
personId: ,
locationId: ,
type:
}

Persons and Locations are tied with Relations as many-to-many.
Relations can be of different types (e.g. "home", "work").
The documents are indexed into the same index with different types:
Person, Location, Relation.

My search should find all Persons which are related to a Location with
Location.name = "someLocation",
and Relation.type = "someType".

I can do that by running a number of queries sequentially:

  1. find Location.id by Location.name (termFilter, filteredQuery);
  2. find all matching Relation.personId by Relation.type and
    Relation.locationId (andFilter, filteredQuery);
  3. find all matching Persons by Person.id (termFilter, filteredQuery).

Is it possible to simplify this search somehow, is there a way to do
it in one query?

Thanks,
Anna

what do you want to achieve? every search index is built with the
domain in mind and so it is very specific. It is often not as generic
as a relational DB, so you probably have to do some de-normalization
(e.g. put all the persons into a location or put the location name and
the person name into the relation and have only relations in the
index ...)

On 31 Aug., 22:18, Anna anna.grigory...@googlemail.com wrote:

Hello,

I am trying to figure out, if there a way to reduce a number of
queries in my search.
I use data model like the following:

Person {
id: ,
name:

}

Location {
id: ,
name:

}

Relation {
personId: ,
locationId: ,
type:

}

Persons and Locations are tied with Relations as many-to-many.
Relations can be of different types (e.g. "home", "work").
The documents are indexed into the same index with different types:
Person, Location, Relation.

My search should find all Persons which are related to a Location with
Location.name = "someLocation",
and Relation.type = "someType".

I can do that by running a number of queries sequentially:

  1. find Location.id by Location.name (termFilter, filteredQuery);
  2. find all matching Relation.personId by Relation.type and
    Relation.locationId (andFilter, filteredQuery);
  3. find all matching Persons by Person.id (termFilter, filteredQuery).

Is it possible to simplify this search somehow, is there a way to do
it in one query?

Thanks,
Anna