I am new to elasticsearch
I am using elasticsearch java-client library to in spring boot application for a global search functionality.I have 5 entity classes with multiple fileds to search for , how can I do that ?
I am now indexing and searching single document , I am attaching the code here.
Help is much appreciated
private void indexData() throws IOException {
List<Project> projectList = projectRepository.findAll();
List<ProjectRequestDto> projectRequestDtoList = projectList.stream().map(ProjectMapper::projectToProjectRequestDtoConvertor).collect(Collectors.toList());
BulkRequest.Builder br = new BulkRequest.Builder();
Jedis jedis = new Jedis("localhost");
for (ProjectRequestDto project : projectRequestDtoList) {
if (jedis.sadd("indexed_project_ids", project.getProjectId()) == 1) {
br.operations(op -> op
.index(idx -> idx
.index("projects")
.id(project.getProjectId())
.document(project)
)
);
}
}
BulkResponse result = client.bulk(br.build());
}
SearchResponse<Project> response = client.search(s -> s
.index("projects", "")
.query(q -> q
.match(t -> t
.field("name")
.field("")
.query(search)
)
),
Project.class
);