-1

I am building an application using Spring boot and elasticsearch (& spring-data-elasticsearch).

I have an entity User that contains a list of regions (i.e each user is responsible for a set of regions).

I have another entity Report that is associated to region (i.e each report has a region)

I want to create indices of report for each user. So that each index contains only the reports of the regions that the user is responsible for.

In this way, when the user search for a report, the search is applied only in his index.

Besides, these indices has to be dynamic (i.e updates if the regions of the user are changed, or new reports are added).

How can I achieve this? Thank you for your help

blue
  • 525
  • 1
  • 8
  • 20

1 Answers1

0

why don't you model user in such way such that user-related information is stored in a row(document), I think nested fields is a good idea, and they can be searched using the nested query so,

for example, each user is responsible for a set of regions so regions can be nested in user since regions are nested they will be stored as a separate document

@Field(type=FieldType.Nested)
private Set<Regions> regions;

secondly, I don't think building a new index every time is a good idea

aditya gupta
  • 403
  • 2
  • 10