Как передать массив объектов в Elastic search High level Rest api - PullRequest
0 голосов
/ 24 мая 2019

Я передаю массив объектов json из пользовательского интерфейса, как показано ниже.

[{
  "name":"Mandoline",
  "description":"A mandoline consists of two parallel working surfaces, one of which can be adjusted in height.[3] A food item is slid along the adjustable surface until it reaches a blade mounted on the fixed surface, slicing it and letting it fall.",
  "type":"creative",
  "link":"/vrushak/files/mandoline.mp3",
  "noofcomments":1,
  "noofviews":2,
  "nooflikes":3,
  "id":7,
  "userobj" :{"user_id":1,name:"test user"}
 },
 {
  "name":"Baratanatyam",
  "description":"Bharatanatyam (Tamil: folk dance) originally known as Sathiraattam(karakattam), is a major genre of Indian classical dance that originated in Tamil Nadu. Traditionally, Bharatanatyam has been a solo dance performed exclusively by women,and it expressed South Indian religious themes and spiritual ideas, particularly of Shaivism, Vaishnavism and Shaktism.",
  "type":"creative",
  "link":"/vrushak/files/baratanatya.mp4",
  "noofcomments":1,
  "noofviews":2,
  "nooflikes":3,
  "id":6,
  "userobj" :{"user_id":2,name:"test user"}
 }]

Приведенный выше массив передан в API поиска эластичного поиска. Ниже приведен код для этого.

@Override
    public void index(Collection<IndexedEntity> entity) throws Exception {
        System.out.println(entity);
        IndexRequest indexRequest = new IndexRequest(index).id("entities");
        entity.forEach(element->{
            convertProfileDocumentToMap(element);
            indexRequest.source(element);//
        });
        IndexResponse indexResponse = client.index(indexRequest, RequestOptions.DEFAULT);
   }




private Map<String, Object> convertProfileDocumentToMap(IndexedEntity profileDocument) {
            return objectMapper.convertValue(profileDocument, Map.class);
        }

Индексированная сущность - это просто модель с теми же полями, что и в массиве json, и тип также совпадает. Я использую цикл foreach, чтобы я мог добавить каждый элемент в индекс, но это не работает (метод индекса выше).

Правильно ли указан код выше? Поскольку указанный выше массив не добавляется в индекс.

Пожалуйста, помогите?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...