GET http://10.192.193.98:9200/shopping/_search?q=title:小米手机
响应结果
{
"took": 772,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 4,
"relation": "eq"
},
"max_score": 0.42144203,
"hits": [
{
"_index": "shopping",
"_type": "_doc",
"_id": "NunonIkBDJDpQI3ST7tm",
"_score": 0.42144203,
"_source": {
"title": "小米手机",
"category": "小米",
"images": "http://www.gulixueyuan.com/xm.jpg",
"price": 3999.00
}
},
{
"_index": "shopping",
"_type": "_doc",
"_id": "N-nonIkBDJDpQI3SXrt6",
"_score": 0.42144203,
"_source": {
"title": "小米手机",
"category": "小米",
"images": "http://www.gulixueyuan.com/xm.jpg",
"price": 3999.00
}
},
{
"_index": "shopping",
"_type": "_doc",
"_id": "OOnonIkBDJDpQI3SbLvp",
"_score": 0.42144203,
"_source": {
"title": "小米手机",
"category": "小米",
"images": "http://www.gulixueyuan.com/xm.jpg",
"price": 3999.00
}
},
{
"_index": "shopping",
"_type": "_doc",
"_id": "OenonIkBDJDpQI3ScbtO",
"_score": 0.42144203,
"_source": {
"title": "小米手机",
"category": "小米",
"images": "http://www.gulixueyuan.com/xm.jpg",
"price": 3999.00
}
}
]
}
}
由于在域名后面添加查询条件不是很方便,所以我们一般使用json格式发送查询条件
GET http://10.192.193.98:9200/shopping/_search
{
"query":{
"match":{
"category":"小米"
}
}
}
GET http://10.192.193.98:9200/shopping/_search
{
"query":{
"match_all":{
}
}
}
GET http://10.192.193.98:9200/shopping/_search
{
"query":{
"match_all":{
}
},
"from":0,
"size":2
}
GET http://10.192.193.98:9200/shopping/_search
{
"query":{
"match_all":{
}
},
"_source":[
"title"
]
}
GET http://10.192.193.98:9200/shopping/_search
{
"query":{
"match_all":{
}
},
"sort":{
"price":{
"order":"desc"
}
}
}
asc
desc
GET http://10.192.193.98:9200/shopping/_search
{
"query":{
"bool":{
"must":[
{
"match":{
"category":"小米"
}
},
{
"match":{
"title":"小米手机"
}
}
]
}
}
}
GET http://10.192.193.98:9200/shopping/_search
{
"query":{
"bool":{
"should":[
{
"match":{
"category":"小米"
}
},
{
"match":{
"category":"华为"
}
}
]
}
}
}
GET http://10.192.193.98:9200/shopping/_search
{
"query":{
"bool":{
"should":[
{
"match":{
"category":"小米"
}
},
{
"match":{
"category":"华为"
}
}
],
"filter":{
"range":{
"price":{
"gt":2598
}
}
}
}
}
}
GET http://10.192.193.98:9200/shopping/_search
{
"query":{
"match_phrase":{
"category":"小"
}
}
}
❗️如果使用match则为全文检索模式,会对查询条件中的内容进行分词,返回包含具有查询条件分词后结果
GET http://10.192.193.98:9200/shopping/_search
{
"query":{
"match":{
"category":"小米"
}
},
"highlight":{
"fields":{
"category":{}
}
}
}
小米
GET http://10.192.193.98:9200/shopping/_search
{
"aggs":{
"price_group":{//为操作起名price_group
"terms":{
"field":"price"
}
},
"price_avg":{
"avg":{
"field":"price"
}
}
},
"size":0
}
响应结果
"aggregations": {
"price_group": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": 3999.0,
"doc_count": 4
},
{
"key": 1999.0,
"doc_count": 1
},
{
"key": 2599.0,
"doc_count": 1
},
{
"key": 2999.0,
"doc_count": 1
}
]
},
"price_avg": {
"value": 3370.4285714285716
}
}
PUT http://10.192.193.98:9200/user/_mapping
{
"properties":{
"name":{
"type":"text",
"index":true
},
"sex":{
"type":"keyword",
"index":true
},
"tel":{
"type":"keyword",
"index":false
}
}
}
GET http://10.192.193.98:9200/user/_mapping