你可以的,加油

同一个文档Match搜索到,但用Term搜索不到

Elasticsearch | 作者 ibamboo | 发布于2017年07月26日 | 阅读数:2298

https://elasticsearch.cn/question/445
看了这个,还是没有解决我的意思。
            var client = BuildClient();
            var query = new SearchDescriptor<ProductIndex>();
// 用match可以搜索到
           query.PostFilter(x => x.Match(m=>m.Field(f=>f.cityName).Query("上海静安")));
// 用term搜索不到
          //  query.PostFilter(x => x.Term(m => m.Field(f => f.cityName).Value("上海静安")));
            var resp = client.Search<ProductIndex>(query);
 
是什么原因,如果搜索英文,或者数字,这两个做法都可以匹配到数据。
我的需求是希望**完全匹配 cityName 为 上海静安 的记录。
 
谢谢解答。
已邀请:

lz8086 - es小司机

赞同来自: xinfanwang

不知道你们用的什么中文分词,猜测:
倒排索引中存的是上海 和 静安
 
使用match时 上海静安,首先会分词为上海和静安 再去倒排索引中去搜,会搜到
 
使用term时,倒排索引中你并没有精确地  上海静安  词项  所以搜不到,
 
看看mapping中cityName这个字段有无cityName.keyword ,如果有用其匹配

rockybean - Elastic Certified Engineer, ElasticStack Fans,公众号:ElasticTalk

赞同来自:

match会分词,term不分词。上海静安 这个词肯定不在分词词库里面

要回复问题请先登录注册