ElasticSearch 操作全解析:从映射管理到查询创建
在 ElasticSearch 的使用过程中,涉及到诸多操作,如映射管理、文档操作、批量处理以及查询创建等。下面将详细介绍这些操作的具体实现和原理。
映射管理
在创建索引后,下一步通常是添加映射。以下是通过原生客户端管理映射的具体步骤:
-准备工作:需要一个正常运行的 ElasticSearch 集群和 Maven。相关代码可在指定位置找到,涉及的类为MappingsOperations。
-代码示例:
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; import org.elasticsearch.client.Client; import org.elasticsearch.common.xcontent.XContentBuilder; import java.io.IOException; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; public class MappingOperations { public static void main( String[] args ) { String index="mytest"; String type="mytyp