#新增第一个商品
PUT /ecommerce/product/1
{
"name":"高露洁牙膏",
"desc":"高效、美白、好用",
"price":33.5,
"producer":"高露洁生产厂家",
"short":"gljyg",
"tags":["防止蛀牙","美白"]
}
#新增第二个商品
PUT /ecommerce/product/2
{
"name":"佳洁士牙膏",
"desc":"高效、好用",
"price":25,
"producer":"高露洁生产厂家",
"short":"jjsyg",
"tags":["防止蛀牙"]
}
#新增第三个商品
PUT /ecommerce/product/3
{
"name":"中华牙膏",
"desc":"高效、美白",
"price":18.6,
"producer":"高露洁生产厂家",
"short":"zhyg",
"tags":["清新","美白"]
}
#查询所有的商品
GET /ecommerce/product/_search
{
"query":{
"match_all": {}
}
}
#! Deprecation: [types removal] Specifying types in search requests is deprecated.
{
"took" : 3,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 3,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "ecommerce",
"_type" : "product",
"_id" : "3",
"_score" : 1.0,
"_source" : {
"name" : "中华牙膏",
"desc" : "高效、美白",
"price" : 18.6,
"producer" : "高露洁生产厂家",
"short" : "zhyg",
"tags" : [
"清新",
"美白"
]
}
},
{
"_index" : "ecommerce",
"_type" : "product",
"_id" : "2",
"_score" : 1.0,
"_source" : {
"name" : "佳洁士牙膏",
"desc" : "高效、好用",
"price" : 25,
"producer" : "高露洁生产厂家",
"short" : "jjsyg",
"tags" : [
"防止蛀牙"
]
}
},
{
"_index" : "ecommerce",
"_type" : "product",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"name" : "高露洁牙膏",
"desc" : "高效、美白、好用",
"price" : 33.5,
"producer" : "高露洁生产厂家",
"short" : "gljyg",
"tags" : [
"防止蛀牙",
"美白"
]
}
}
]
}
}
GET /ecommerce/product/_search
{
"query":{
"match_all": {}
},
"sort":{
"price":{
"order":"asc"}}
}
Text fields are not optimised for operations that require per-document field data like aggregations and sorting, so these operations are disabled by default. Please use a keyword field instead. Alternatively, set fielddata=true on [price] in order to load field data by uninverting the inverted index. Note that this can use significant memory.
https://www.elastic.co/guide/en/elasticsearch/reference/current/fielddata.html
PUT /ecommerce/product/_mapping
{
"properties": {
"price": {
"type": "text",
"fielddata": true
}
}
}
事实证明官方给的方法没啥乱用
,只解决了一半的问题,并无卵用
Types cannot be provided in put mapping requests, unless the include_type_name parameter is set to true.
错误提示
告诉我们要加一个include_type_name
参数。
PUT /ecommerce/product/_mapping?include_type_name=true
{
"properties": {
"price": {
"type": "text",
"fielddata": true
}
}
}
按照这个错误提示,完美解决上面的问题。