如何在elasticsearch中创建多个索引

时间:2017-09-01 12:18:25

标签: java elasticsearch

我是Elastic search的新手,我有一个User类,它将主题和专业知识类作为复合类。

public class User {
    private String auth0Id;
    private String firstName;
    private String lastName;
    private String email;
    private Set<Topic> interests = new HashSet<Topic>();
    private Set<Expertise> expertise = new HashSet<Expertise>();
}

我从我的数据库中获取此信息并想要将其编入索引。我做了以下

Iterable<User> results = userService.getAll();
com.fasterxml.jackson.databind.ObjectMapper mapper = new com.fasterxml.jackson.databind.ObjectMapper();
int i = 0;
Node node = nodeBuilder().node();
Client client = node.client();
    try {
        for (User userObj : results) {
        UserTO userTo = new UserTO();
        userTo = marshall(userObj);
        IndexResponse response = client.prepareIndex("member","member")
                            .setSource(mapper.writeValueAsString(userTo)).execute()
                            .actionGet();
        i++;
        log.debug("User/Member " + userObj.getEmail() + " (" + response.getId() + ") has been updated");
        }
        log.info(i + " user/members indexed");
        log.info(i + " user/members indexed");
        } catch (Exception ex) {
                ex.printStackTrace();
   } 

我想添加兴趣和专业知识的索引,以便当用户搜索姓名或专业知识或兴趣时,应显示所有具有姓名或专业知识或兴趣的用户。

0 个答案:

没有答案