Search in sources :

Example 26 with IndexQuery

use of org.springframework.data.elasticsearch.core.query.IndexQuery in project spring-data-elasticsearch by spring-projects.

the class NestedObjectTests method shouldIndexMultipleLevelNestedObjectWithIncludeInParent.

@Test
public void shouldIndexMultipleLevelNestedObjectWithIncludeInParent() {
    // given
    List<IndexQuery> indexQueries = createPerson();
    // when
    operations.bulkIndex(indexQueries, IndexCoordinates.of("test-index-person-multiple-level-nested"));
    // then
    Map<String, Object> mapping = operations.indexOps(PersonMultipleLevelNested.class).getMapping();
    assertThat(mapping).isNotNull();
    Map<String, Object> propertyMap = (Map<String, Object>) mapping.get("properties");
    assertThat(propertyMap).isNotNull();
    Map bestCarsAttributes = (Map) propertyMap.get("bestCars");
    assertThat(bestCarsAttributes.get("include_in_parent")).isNotNull();
}
Also used : IndexQuery(org.springframework.data.elasticsearch.core.query.IndexQuery) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.jupiter.api.Test) SpringIntegrationTest(org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)

Example 27 with IndexQuery

use of org.springframework.data.elasticsearch.core.query.IndexQuery in project HuaXing-learningCenter by 17666555910.

the class BaseServiceImpl method batchInsertOrUpdate.

@Override
public void batchInsertOrUpdate(List<T> entityModelList) {
    if (CollectionUtils.isEmpty(entityModelList)) {
        throw new CommonException("entityModelList Can't be empty");
    }
    // 判断索引是否存在 若不存在则创建索引和映射
    if (!elasticsearchTemplate.indexExists(getEntityClass())) {
        this.createEntityEsIndex();
    }
    List<IndexQuery> queries = new ArrayList<>();
    for (T entityEsModel : entityModelList) {
        IndexQuery indexQuery = new IndexQueryBuilder().withId(entityEsModel.getId()).withObject(entityEsModel).build();
        queries.add(indexQuery);
    }
    // 批量插入
    this.bulkInsert(queries);
}
Also used : IndexQueryBuilder(org.springframework.data.elasticsearch.core.query.IndexQueryBuilder) IndexQuery(org.springframework.data.elasticsearch.core.query.IndexQuery) ArrayList(java.util.ArrayList) CommonException(com.huaxing.springboot_elasticsearch.common.utils.CommonException)

Example 28 with IndexQuery

use of org.springframework.data.elasticsearch.core.query.IndexQuery in project fh by assecopl.

the class GenericDtoService method reindexPage.

public Slice<ENTITY> reindexPage(Pageable pageable, Class dtoClass, String indexName, String indexType) {
    Slice<ENTITY> slice = getJpaRepository().findAll(pageable);
    List<DTO> dtoList = mapEntityToDtoForBulkReindex(slice.getContent());
    List<IndexQuery> queries = new ArrayList<>();
    for (DTO dto : dtoList) {
        IndexQuery indexQuery = new IndexQuery();
        indexQuery.setId(dto.getId().toString());
        indexQuery.setObject(dto);
        // if (StringUtils.isNotBlank(indexType))
        // indexQuery.setType(getDtoEsIndexType(dtoClass));
        queries.add(indexQuery);
    }
    IndexCoordinates indexCoordinates = elasticsearchTemplate.getIndexCoordinatesFor(listClazz);
    elasticsearchTemplate.bulkIndex(queries, indexCoordinates);
    queries.clear();
    return slice;
}
Also used : IndexQuery(org.springframework.data.elasticsearch.core.query.IndexQuery) IndexCoordinates(org.springframework.data.elasticsearch.core.mapping.IndexCoordinates)

Example 29 with IndexQuery

use of org.springframework.data.elasticsearch.core.query.IndexQuery in project demo by breeze0630.

the class ElasticsearchTemplateTest method testInsert.

@Test
public void testInsert() {
    Commodity commodity = new Commodity();
    commodity.setSkuId("1501009005");
    commodity.setName("葡萄吐司面包(10片装)");
    commodity.setCategory("101");
    commodity.setPrice(160);
    commodity.setBrand("良品铺子");
    IndexQuery indexQuery = new IndexQueryBuilder().withObject(commodity).build();
    elasticsearchTemplate.index(indexQuery);
}
Also used : IndexQueryBuilder(org.springframework.data.elasticsearch.core.query.IndexQueryBuilder) Commodity(com.example.esdemo.dto.Commodity) IndexQuery(org.springframework.data.elasticsearch.core.query.IndexQuery) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 30 with IndexQuery

use of org.springframework.data.elasticsearch.core.query.IndexQuery in project IT-Demo by yanghaiji.

the class EsRestTemplateImpl method index.

public String index() {
    UserEntity userEntity = UserEntity.builder().id(System.currentTimeMillis()).brand("javayh").images("es.png").price(2020.29).title("Java有货").build();
    IndexQuery indexQuery = new IndexQueryBuilder().withObject(userEntity).build();
    String sys_user = elasticsearchTemplate.index(indexQuery, IndexCoordinates.of("sys_user"));
    return sys_user;
}
Also used : IndexQueryBuilder(org.springframework.data.elasticsearch.core.query.IndexQueryBuilder) IndexQuery(org.springframework.data.elasticsearch.core.query.IndexQuery) UserEntity(com.javayh.elaticsearh.docment.UserEntity)

Aggregations

IndexQuery (org.springframework.data.elasticsearch.core.query.IndexQuery)31 Test (org.junit.jupiter.api.Test)12 SpringIntegrationTest (org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest)9 ArrayList (java.util.ArrayList)8 IndexCoordinates (org.springframework.data.elasticsearch.core.mapping.IndexCoordinates)8 DisplayName (org.junit.jupiter.api.DisplayName)4 IndexQueryBuilder (org.springframework.data.elasticsearch.core.query.IndexQueryBuilder)4 NativeSearchQuery (org.springframework.data.elasticsearch.core.query.NativeSearchQuery)4 NativeSearchQueryBuilder (org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder)4 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)3 HashMap (java.util.HashMap)2 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 SeqNoPrimaryTerm (org.springframework.data.elasticsearch.core.query.SeqNoPrimaryTerm)2 Commodity (com.example.esdemo.dto.Commodity)1 CommonException (com.huaxing.springboot_elasticsearch.common.utils.CommonException)1 UserEntity (com.javayh.elaticsearh.docment.UserEntity)1 Field (java.lang.reflect.Field)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Collection (java.util.Collection)1