按预定顺序获取结果

时间:2019-01-27 13:17:59

标签: elasticsearch

希望将结果按照我选择的特定顺序排序,而不是简单地递增或递减。

道路的location_object_code为2,城镇为1,城市为3。

GET location_object/_search
{
  "size": 100,
  "sort": [{ 
        "road": {
            "unmapped_type": "long" 
            }
        },
        { "town": {
              "unmapped_type": "long" 
            }
        },
        { "city": {
            "unmapped_type": "long" 
            }
        }
  ],  
      "query": {
        "multi_match": {
          "query": "1 2 3 4",
          "fields": ["*.location_object_code"],
          "operator": "or"
        }
      }
  }

我希望结果首先返回道路,然后返回城镇,然后返回城市。 我无法按location_object_code排序,因为我想要的顺序是2,1、3

所有三个对象的映射相同:

  {  
   "location_object":{  
      "properties":{  
         "area":{  
            "properties":{  
               "properties":{  
                  "type":"object"
               }
            }
         },
         "description":{  
            "type":"text"
         },
         "location":{  
            "properties":{  
               "properties":{  
                  "type":"object"
               }
            }
         },
         "road_name":{  
            "type":"keyword"
         },
         "location_object_code":{  
            "type":"keyword"
         },
         "location_object_name":{  
            "type":"keyword"
         },
         "synonyms":{  
            "type":"text",
            "fields":{  
               "complete":{  
                  "type":"completion",
                  "analyzer":"simple",
                  "preserve_separators":true,
                  "preserve_position_increments":true,
                  "max_input_length":50
               },
               "keywordstring":{  
                  "type":"keyword"
               }
            }
         }
      }
   }
}

0 个答案:

没有答案
相关问题