转载请标明出处:
http://blog.zhanbaozhan.com/qq_27818541/article/details/109225014
本文出自:【BigManing的博客】
一般用于排序时,该字段没有值,使用missing赋值默认值(默认为”_last“),然后就用赋的值进行排序。
场景: 旧doc中price字段无值,新doc中price字段有值,在排序时就可以使用missing设置默认值。
例如:
GET /_search
{
"sort" : [
{ "price" : {"missing" : "_last"} }
],
"query" : {
"term" : { "title" : "BigManing" }
}
}
如果mapping中无此字段,则搜索请求将失败。unmapped_type选项允许您忽略没有mapping的字段,也不按它们排序。参数的值为该字段对应值的类型。
场景:在滚动index中,旧index没有price字段,新index有price字段。如果想按照price进行sort而不报错,就需要使用unmapped_type。
例如:
GET /_search
{
"sort" : [
{ "price" : {"unmapped_type" : "long"} }
],
"query" : {
"term" : { "title" : "BigManing" }
}
}
如果mamppnig中不存在该字段,进行query,会报错No mapping found for [price] in order to sort on
。
{
"error": {
"root_cause": [
{
"type": "query_shard_exception",
"reason": "No mapping found for [price] in order to sort on",
"index_uuid": "B6kE8KesTSiqB4rdr_BWkg",
"index": "book-20201021"
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "book-20201021",
"node": "bfSazPXfRjSI2P_cg5XsEQ",
"reason": {
"type": "query_shard_exception",
"reason": "No mapping found for [price] in order to sort on",
"index_uuid": "B6kE8KesTSiqB4rdr_BWkg",
"index": "book-20201021"
}
}
]
},
"status": 400
}
信息加载中,请等待
微信客服(速回)
微信客服(慢回)