use of org.springframework.data.elasticsearch.core.query.IndexQueryBuilder in project spring-data-elasticsearch by spring-projects.
the class AbstractElasticsearchTemplate method getIndexQuery.
private <T> IndexQuery getIndexQuery(T entity) {
String id = getEntityId(entity);
if (id != null) {
id = elasticsearchConverter.convertId(id);
}
// noinspection ConstantConditions
IndexQueryBuilder builder = //
new IndexQueryBuilder().withId(//
id).withObject(entity);
SeqNoPrimaryTerm seqNoPrimaryTerm = getEntitySeqNoPrimaryTerm(entity);
if (seqNoPrimaryTerm != null) {
builder.withSeqNoPrimaryTerm(seqNoPrimaryTerm);
} else {
// version cannot be used together with seq_no and primary_term
// noinspection ConstantConditions
builder.withVersion(getEntityVersion(entity));
}
String routing = getEntityRouting(entity);
if (routing != null) {
builder.withRouting(routing);
}
return builder.build();
}
use of org.springframework.data.elasticsearch.core.query.IndexQueryBuilder 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);
}
use of org.springframework.data.elasticsearch.core.query.IndexQueryBuilder 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);
}
use of org.springframework.data.elasticsearch.core.query.IndexQueryBuilder 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;
}
use of org.springframework.data.elasticsearch.core.query.IndexQueryBuilder in project IT-Demo by yanghaiji.
the class EsRestTemplateImpl method insertItemDocBulk.
/**
* <p>
* 批量信息
* </p>
*
* @param
* @return void
* @version 1.0.0
* @author hai ji
* @since 2022/2/9
*/
public void insertItemDocBulk() {
List<IndexQuery> list = new ArrayList<>();
list.add(new IndexQueryBuilder().withObject(UserEntity.builder().id(System.currentTimeMillis()).brand("javayh").images("es.png").price(2020.29).title("Java有货").build()).build());
list.add(new IndexQueryBuilder().withObject(UserEntity.builder().id(System.currentTimeMillis() + 1).brand("javayh").images("es.png").price(2020.29).title("Java有货").build()).build());
elasticsearchTemplate.bulkIndex(list, IndexCoordinates.of("sys_user"));
}
Aggregations