2016-04-09 67 views
1
{ 
    "users": [ 
     { 
      "type": "admin", 
      "date": "2016-03-02T12:34:00+08:00", 
      "status": "2" 
     }, 
     { 
      "type": "staff", 
      "date": "2016-03-02T12:34:00+08:00", 
      "status": "2" 
     } 
    ], 
    "features": "1 2 3 4 5" 
} 

可以说我有上面的Elasticsearch文档结构。我想获取该索引中的所有文档,但具有功能3的应该位于搜索结果的顶部/行尾。我通过Elasticsearch文档,但我无法弄清楚如何去做。谁能帮我这个 ?如何基于匹配属性对弹性搜索查询进行排序?

+0

什么的'features'领域的映射? –

+0

string @AndreiStefan – ehp

回答

0

使用此查询:

{ 
    "query": { 
    "bool": { 
     "should": [ 
     { 
      "match": { 
      "features": "3" 
      } 
     }, 
     { 
      "match_all": {} 
     } 
     ] 
    } 
    } 
} 
+0

太棒了!这工作得很好。你可以分享一些链接/教程,从我可以学习自己写这种类型的查询?谢谢。 – ehp