
数据格式如下,要求精确的搜索出 tags:"文字" 的记录 :
{ "_index" : "xxx", "_type" : "xxx", "_id" : "123", "_version" : 1, "_score" : 1, "_source" : { "iD" : 123, "name" : "xxx", "tags" : [ "文字", "恋爱", "冒险" ], "keywords" : [] } } 我在搜索的时候 tags:"文字" 的时候,会把下面的数据也检索出来,怎么精准的只搜索出 上面这个记录呢?
{ "_index" : "xxx", "_type" : "xxx", "_id" : "124", "_version" : 1, "_score" : 1, "_source" : { "iD" : 123, "name" : "xxx", "tags" : [ "A 文字 A", "恋爱", "冒险" ], "keywords" : [] } } 1 slixurd 2016 年 6 月 24 日 用 term 搜索。另外 mappings 需要把 index 改成 not_analyzed 。因为默认是 standard analyzer ,所以 stop words 就被隔开了。 |
3 WinterWu 2016 年 6 月 25 日 via iPhone es 文档已经很全了,但是功能确实复杂。 |
4 dbfox OP |
6 slixurd 2016 年 6 月 25 日 |
8 dbfox OP |
9 dbfox OP @slixurd 我用的 C# 客户端,重建了索引,依然不行,我测试下你的例子 [String(Index = FieldIndexOption.NotAnalyzed)] using Nest; using System; namespace Common.ElasticSearch.Entities { [ElasticsearchType(IdProperty = "ID")] public class TopicEntity { public int ID { get; set; } [String(Index = FieldIndexOption.NotAnalyzed)] public string Key { get; set; } [String(Index = FieldIndexOption.NotAnalyzed)] public string Name { get; set; } [String(Index = FieldIndexOption.NotAnalyzed)] public string[] Tags { get; set; } /// <summary> /// 关键字 /// </summary> public string[] Keywords { get; set; } /// <summary> /// 热度 /// </summary> public int Hot { get; set; } } } |
11 slixurd 2016 年 6 月 26 日 C#我就不懂了,我是 Java 党。你加油。 |