在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Java/ elasticsearch排序問題

elasticsearch排序問題

使用completion suggester,然后在搜索建議中怎么對搜索出來的結(jié)果進(jìn)行排序?我有一個search_count字段,想按照這個字段排序`GET movie/douban/_search?pretty
{

"suggest": {
    "my_suggest" : {
        "text":"檸檬", 
        "completion" : { 
            "field" : "suggest",
            "size":10
        },
        "sort":{
          "search_count":{
            "order":"desc"
          }
        }
    }
    
    
}

}`
這樣寫會提示suggester with name [sort] not supported

GET movie/douban/_search?pretty
{
    "suggest": {
        "my_suggest" : {
            "text":"檸檬", 
            "completion" : { 
                "field" : "suggest",
                "size":10
            }
        }
    },
    "sort":{
      "search_count":{
        "order":"desc"
      }
    }
}

這樣寫的話不報錯但是也根本沒有排序

這是數(shù)據(jù)大概樣式`"suggest": {

"my_suggest": [
  {
    "text": "檸檬",
    "offset": 0,
    "length": 2,
    "options": [
      {
        "text": "檸檬",
        "_index": "movie",
        "_type": "douban",
        "_id": "2042618",
        "_score": 1,
        "_source": {
          "name": "檸檬時期 / The Graduates",
          "img": "https://img3.doubanio.com/view/movie_poster_cover/lpst/public/p2176652956.jpg",
          "suggest": [
            {
              "input": [
                "檸檬時期 / The Graduates"
              ],
              "weight": 1
            },
            {
              "input": [
                "檸",
                "時期",
                "檬",
                "檸檬",
                "graduates"
              ],
              "weight": 1
            },
            {
              "input": [
                "檸檬のころ"
              ],
              "weight": 1
            },
            {
              "input": [
                "檸",
                "こ",
                "ろ",
                "の"
              ],
              "weight": 5
            }
          ],
          "nike_name": "檸檬のころ",
          "search_count": 0,
          "pubdate": "2007-03-31"`

求指導(dǎo)正確格式,或者給出一個能代替的方法只要可以按照某個字段查詢即可

回答
編輯回答
吢涼

對搜索結(jié)果進(jìn)行排序的話,用filter 試試,
下面貼一個我真實用到的一個dsl,包含排序,聚合,過濾等。

{
    "size":2,
    "_source":["title","ptitle","gentuanyouid","startline","hits","daytype"],
    "sort":{
        "updatetime":{
            "order":"desc"
        }    
    },
    "query":{
        "bool":{
                "filter":{
                       "bool":{
                            "must":[
                                
                                {
                                    "match_phrase":{
                                        "startline":"|5993-5958"
                                    }    
                                },
                                {
                                    "term":{
                                            "online":"1"
                                    }
                                },
                                {
                                    "term":{
                                            "shenhe":"1"
                                    }
                                }
                                ,
                                {
                                    "term":{
                                            "del":"0"
                                    }
                                } 
                            ]
                        }
                }
        }
    },
    "aggs":{
        "tongjis":{
            "terms":{
                "field":"endline.keyword",
                "size":20
            }
        }
    }
    
    
    
    
    
}
2018年8月7日 19:00