Index and search multiple indices and fields

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
        );

You should use the multi_match query in that case.

See

I am using java-client api 8.7

solved

        SearchResponse<ElasticRequestDto> response = client.search(s -> s
                        .index("documents")
                        .query(q -> q
                                .multiMatch(m -> m
                                        .fields("title", "description", "uniqueId", "additionalField")
                                        .query(search)
                                )
                        ),
                ElasticRequestDto.class
        );

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.