ElasticSearch3:Query
来源:互联网 发布:机械运动仿真软件 编辑:程序博客网 时间:2024/05/16 06:23
1.Query string search
1)GET /ecommerce/product/_search
查询所有的匹配/ecommerce/product的数据
{
"took": 8,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 3,
"max_score": 1,
"hits": [
{
"_index": "ecommerce",
"_type": "product",
"_id": "2",
"_score": 1,
"_source": {
"name": "jiajieshi yao",
"desc": "youxiao fangzhu",
"price": 25,
"producer": "jiajieshi producer",
"tags": [
"fangzhu"
]
}
},
{
"_index": "ecommerce",
"_type": "product",
"_id": "1",
"_score": 1,
"_source": {
"name": "gaolujie yao",
"desc": "gaoxiao meibai",
"price": 30,
"producer": "gaolujie producer",
"tags": [
"fangzhu",
"meibai"
]
}
},
{
"_index": "ecommerce",
"_type": "product",
"_id": "3",
"_score": 1,
"_source": {
"name": "zhonghua yao",
"desc": "caoben zhiwu",
"price": 40,
"producer": "zhonghua producer",
"tags": [
"qingxing"
]
}
}
]
}
}
2)GET /ecommerce/product/_search?q=name:zhonghua&sort=price:desc 条件查询:获取name中含zhonghua字符的数据
{
"took": 17,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 1,
"max_score": null,
"hits": [
{
"_index": "ecommerce",
"_type": "product",
"_id": "3",
"_score": null,
"_source": {
"name": "zhonghua yao",
"desc": "caoben zhiwu",
"price": 40,
"producer": "zhonghua producer",
"tags": [
"qingxing"
]
},
"sort": [
40
]
}
]
}
}
2.query DSL(Domain Spcialify Language)
1)查询ecommerce/product下所有的数据GET /ecommerce/product/_search
{
"query":{
"match_all": {}
}
}
2)模糊查询
{
"query":{
"match": {
"name": "yao"
}
},
"sort": [
{
"price": "desc"
}
]
}
4)query分页查询
{
"query":{"match_all":{}},
"from": 1,
"size": 2,
"sort": [
{
"price":"desc"
}
]
}
3.query source查询
5)query source :可以进行选择字段进行显示
{
"query":{"match_all": {}},
"_source": ["name","price"]
}
4.query filter查询
6)query filter检索
GET /ecommerce/product/_search
{
"query":{
"bool":{
"must":{
"match":{
"name":"yao"
}
},
"filter": {
"range":{
"price":{
"lte": 30
}
}
}
}
}
}
5.全文检索查询
7)全文检索
{
"name":"special meibai yao",
"desc":"special meibai",
"price":50,
"producer":"special yagao producer",
"tags":["meibai"]
}
GET /ecommerce/product/4
GET /ecommerce/product/_search
{
"query":{
"match":{
"producer":"yagao producer"
}
}
}
普通匹配查询
{
"query":{
"match":{
"name":"yao"
}
}
}
6.字面匹配查询
8)字面匹配查询,必须包含字符串查询
{
"query":{
"match_phrase":{
"producer": "yagao"
}
}
}
7.高亮查询
9)高亮查询,并设置高亮的字符串,查询的结果中对应的字符串就会被<em>包围
{
"query":{
"match":{
"producer":"yagao"
}
},
"highlight":{
"fields": {
"producer":{}
}
}
}