NEST 字符串sort

text字符串sort會先分詞。可先建立filed字段。並設置爲keyword

mapping

        public void Mapping()
        {
            var response = client.IndexExists("employee");
            if (!response.Exists)
            {
                client.CreateIndex("employee");
            }
            client.Map<employee>(m => m.Properties(p => p.Text(t => t.Name("last_name").Fielddata().Analyzer("english").Fields(f=>f.Keyword(k=>k.Name("raw"))))).AutoMap());
        }

  

sort

        public void Sort()
        {
           // client.Search<employee>(s => s.Query(q => q.Bool(b => b.Filter(f => f.Term(t => t.Field("last_name").Value("test01"))))).Pretty());
            client.Search<employee>(s =>
                s.Query(q =>
                    q.ConstantScore(c =>
                        c.Filter(f =>
                            f.Term(t =>
                                t.Field("age").Value("26")
                                ))))
                    .Sort(so => 
                    so.Descending("last_name")
                     )
                    .Pretty());

        }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章