利用head插件:
1,创建索引并添加一条数据(yananindex:索引名称,yanantype:索引类型,1:索引id)
2.修改索引数据(索引id1不变,_version是对该索引数据执行了几次修改,created:false代表是修改)
3.1,删除数据
3.2删除索引
java方式:(elasticsearchTemplate为spring注解获取的elasticsearch客户端)
1.增改(没有索引自动创建,已有索引和数据自动更新)
package org.springframework.data.elasticsearch.core.query;
List<IndexQuery> indexQueries = new ArrayList<IndexQuery>();
IndexQuery indexQuery1 = new IndexQueryBuilder().withId(yanan.getId()+"").withIndexName("yananindex").withObject(yanan).build();
indexQueries.add(indexQuery1);
try{
elasticsearchTemplate.bulkIndex(indexQueries);
elasticsearchTemplate.refresh(Yanan.class, true);
}catch(Exception e){
e.printStackTrace();
}
2.查询
NativeSearchQueryBuilder searchQuery = new NativeSearchQueryBuilder();
BoolQueryBuilder bqb = QueryBuilders.boolQuery();
searchQuery.withIndices("yananindex");
searchQuery.withPageable(new PageRequest(pageUtil.getCurrentPage()-1, 20));
bqb.mustNot(QueryBuilders.termQuery("gender", "male"));
list = elasticsearchTemplate.queryForList(searchQuery.build(),Yanan.class);
3.删除