elasticsearch-partitioner

Elasticsearch auto patition, deep pagination, search after, aggregation

License

License

Categories

Categories

Search Business Logic Libraries Elasticsearch
GroupId

GroupId

io.github.snowthinker
ArtifactId

ArtifactId

elasticsearch-helper
Last Version

Last Version

0.0.3-RELEASE
Release Date

Release Date

Type

Type

jar
Description

Description

elasticsearch-partitioner
Elasticsearch auto patition, deep pagination, search after, aggregation
Project URL

Project URL

https://github.com/snowThinker/elasticsearch-helper
Source Code Management

Source Code Management

https://github.com/snowThinker/elasticsearch-helper

Download elasticsearch-helper

How to add to project

<!-- https://jarcasting.com/artifacts/io.github.snowthinker/elasticsearch-helper/ -->
<dependency>
    <groupId>io.github.snowthinker</groupId>
    <artifactId>elasticsearch-helper</artifactId>
    <version>0.0.3-RELEASE</version>
</dependency>
// https://jarcasting.com/artifacts/io.github.snowthinker/elasticsearch-helper/
implementation 'io.github.snowthinker:elasticsearch-helper:0.0.3-RELEASE'
// https://jarcasting.com/artifacts/io.github.snowthinker/elasticsearch-helper/
implementation ("io.github.snowthinker:elasticsearch-helper:0.0.3-RELEASE")
'io.github.snowthinker:elasticsearch-helper:jar:0.0.3-RELEASE'
<dependency org="io.github.snowthinker" name="elasticsearch-helper" rev="0.0.3-RELEASE">
  <artifact name="elasticsearch-helper" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.github.snowthinker', module='elasticsearch-helper', version='0.0.3-RELEASE')
)
libraryDependencies += "io.github.snowthinker" % "elasticsearch-helper" % "0.0.3-RELEASE"
[io.github.snowthinker/elasticsearch-helper "0.0.3-RELEASE"]

Dependencies

compile (6)

Group / Artifact Type Version
org.springframework : spring-context jar 5.1.6.RELEASE
org.springframework : spring-web jar 5.1.6.RELEASE
org.springframework.data : spring-data-elasticsearch jar 3.1.9.RELEASE
com.fasterxml.jackson.datatype : jackson-datatype-jsr310 jar 2.9.9
com.fasterxml.jackson.core : jackson-annotations jar 2.9.9
io.github.snowthinker : pojo-helper jar 0.0.3-RELEASE

provided (1)

Group / Artifact Type Version
org.projectlombok : lombok jar 1.18.6

test (1)

Group / Artifact Type Version
junit : junit jar 4.10

Project Modules

There are no modules declared in this project.

elasticsearch-helper ES助手(https://github.com/snowThinker/elasticsearch-helper)

Maven Central License

主要功能

  • ElasticsearchTemplate深度分页支持:重写ElasticsearchTemplate支持 search after 深度分页
  • 自动创建分区及自动分区指向:可按月分区索引,每月创建索引,自动别名指向功能
  • Elasticsearch 读写分离:读写分离, 读操作所有索引分区,写只操作当月索引

如何使用

1、添加pom依赖

<dependency>
    <groupId>io.github.snowthinker</groupId>
    <artifactId>elasticsearch-helper</artifactId>
    <version>0.0.2-RELEASE</version>
</dependency>

2、初始化CustomElasticsearchTemplate

@Bean
public CustomElasticsearchTemplate customElasticsearchTemplate(Client client) {
	return new CustomElasticsearchTemplate(client, new CustomDefaultResultMapper());
}

3、JavaBean编写

@Data
public class Item implements Serializable {	
	@Id
	private String id;
	
	@Field
	private String name;
	
	@Field
	private String sku;
}

4、深度分页

int pageSize = 10;

// 深度分页
Object[] searchAfters = new Object[]{"Iphone", "_id"};

// 排序必需和深度分页顺序相一致
SortBuilder[] orders = new SortBuilder[2];
orders[0] = SortBuilders.fieldSort("name.keyword").order(SortOrder.DESC);
orders[1] = SortBuilders.fieldSort("id.keyword").order(SortOrder.DESC);

// 条件查询
QueryBuilder queryBuilder = QueryBuilders.termQuery("name", "Iphone");
SearchQuery searchQuery = new NativeSearchQueryBuilder()
		.withIndices("item")
		.withQuery(queryBuilder)
		.build();

Page<Item> pageResult = customElasticsearchTemplate.searchAfter(searchQuery, Arrays.asList(orders), searchAfters, pageSize, Item.class);

List<Item> dataList = pageResult.get().collect(Collectors.toList());

log.info("Total Record: {}, page list: {}", pageResult.getTotalElements(), dataList);

5、打印DSL日志

<logger name="org.springframework.data.elasticsearch.core.QUERY" level="DEBUG"/>

Versions

Version
0.0.3-RELEASE
0.0.2-RELEASE
0.0.1-RELEASE