一、ES简单查询
查询主要有如下几种:
1、query string search
2、query DSL
3、query filter
4、full-text search
5、phrase search
6、highlight search
1.1、query string search
搜索全部商品:GET /ecommerce/product/_search
GET /ecommerce/product/_search { "took": 3, #耗费了几毫秒 "timed_out": false, #是否超时,这里是没有 "_shards": { #数据拆成了5个分片,所以对于搜索请求,会打到所有的primary shard(或者是它的某个replica shard也可以) "total": 5, "successful": 5, "failed": 0 }, "hits": { "total": 4, #查询结果的数量,4个document "max_score": 1, #score的含义,就是document对于一个search的相关度的匹配分数,越相关,就越匹配,分数也高 "hits": [ #包含了匹配搜索的document的详细数据 { "_index": "ecommerce", "_type": "product", "_id": "1_update", "_score": 1, "_source": { "doc": { "name": "jiaqiangban gaolujie yaogao" } } }, { "_index": "ecommerce", "_type": "product", "_id": "2", "_score": 1, "_source": { "name": "jiajieshi yagao", "desc": "youxiao fangzhu", "price": 25, "producer": "jiajieshi producer", "tags": [ "fangzhu" ] } }, { "_index": "ecommerce", "_type": "product", "_id": "1", "_score": 1, "_source": { "name": "gaolujie yagao", "desc": "gaoxiao meibai", "price": 30, "producer": "gaolujie producer", "tags": [ "meibai", "fangzhu" ] } }, { "_index": "ecommerce", "_type": "product", "_id": "3", "_score": 1, "_source": { "name": "zhonghua yagao", "desc": "caoben zhiwu", "price": 40, "producer": "zhonghua producer", "tags": [ "qingxin" ] } } ] } }