1,elastic search的服务安装在本地192.168.25.101的虚拟机上,先启动es的服务。在进行索引查询之前,首先建立索引库, 并向索引库中添加测试的索引信息。执行以下的命令后:(1)创建了INDEX = store,TYPE = books的索引库 (2) 向索引库中添加了id=1,以及id=2 的两条索引记录。



2,构造termQuery对象进行字符的精确匹配查询
项目中引用的maven依赖仍然是elasticsearch 2.3.5的jar
(1) 下面是用es的termQuery对象构造查询语句,精确查询price = “35.99”的书籍信息。以下es查询语句相当于 sql语句:select * from books where price = 35.99。下面的代码中首先是获取transportClient对象,之后构造searchRequestBuilder的对象, 然后通过searchRequestBuilder对象发送http请求进行查询。下面代码运行后打印出来的searchRequesrBuilder 的内容如下:












网友评论