Advice on how to best structure my mappings


(Harley) #1

Currently, I have two kinds of data in Elasticsearch. The first is company and the second is location. A company entry would hold information such as name, profit, sector etc. A location entry would hold the address and contact methods. A company can have multiple locations (there can be 1000s of them and there are around 3000 companies).

The project at the moment is structured so that the data gets loaded from a database into Elasticsearch. The project that loads it also converts the data into the correct form for our Elasticsearch indices. Then when searching this data, I get the locations and companies and put them together into a list of responses to the front end.

I also have a couple of problems related to how to best use the data:

  • On my search results page, I want to show a list of offices and nested underneath them, I want to display all of the offices. However, I want to paginate by company. So say I get 1000 results for a search, I want to return the first 20 companies and then underneath them, I want to show 20 offices (with more pagination).
  • The other issue is how to structure our data for filters. I need to be able to filter by country and city. When a search is made, you would have the option to filter by the available countries and locations but these locations would have to come from the Elasticsearch somehow.

My questions:

  1. Is there someway I can group the locations underneath companies so that it is almost like a separate query with it's own pagination? Or should I do another request to Elasticsearch to collect information about offices?
  2. Should data be separated like it is (companies and locations)? Given the size of the data, would it be a bad idea to store all locations for a company in the same document as the company they belong to? I have Redis available so I can store minimal amounts of information about each location in Elasticsearch to keep the size down.
  3. How can I structure the offices efficiently? If I hold it all in one document, would a format like the following be efficient?
  • Locations
    • United Kingdom
      • London
      • Liverpool
      • Newcastle
    • France
      • Paris
      • Lyon
      • Nice

Sorry for the vague nature of the question, I am hoping for some advice.