简体   繁体   中英

Search/retrieve by a large OR query clause with Solr or Elasticsearch

I have a search database of car models: "Nissan Gtr", "Huynday Elantra", "Honda Accord", etc...

Now I also have a user list and the types of cars they like user1 likes: carId:1234, carId:5678 etc...

Given user 1 I would like to return all the cars he likes, it can be 0 to even hundreads.

What the best way to model this in Solr or potentially another "nosql" system that can help with this problem.

I'm using Solr but I have the opportunity to use another system if I can and if it makes sense.

EDIT: Solr solution is to slow for Join (Maybe we can try nested). And the current MySQL solution which uses join tables has over 2 billion rows.

so, you just want to store a mapping between User->Cars, and retrieve the cars based on the user...sounds very simple:

  1. Your docs are Users: contain id (indexed), etc fields
  2. one of the field is 'carsliked', multivalued, which contains the set of car ids he likes
  3. you have details about each care in a different collection for example.
  4. given a user id, you retrieve the 'carsliked' field, and get the car details with a cross collection join

    You could also use nested object to store each liked car (with all the info about it) inside each user, but is a bit more complex. As a plus, you don't need the join on the query.

Solr would allow you many more things, for example, given a car, which users do like it? Elasticsearch will work exactly the same way (and probably many other tools, given how simple your use case seems).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM