我正在运行一个基本上创建URL缩短器的应用程序,当我设置大写和小写的“shorurl”时,我无法获得查询或过滤器来查找它。然而,对于更简单的其他领域,它工作得很好。我试着做小写,但不确定如何匹配。
这是字段定义:
[ElasticProperty(Name = "shorturl", IncludeInAll = true)]
public string ShortUrl { get; set; }
以下是一个例子:
string url = "http://test.com/JjdWtPoV";
FilterContainer filter = new FilterContainer();
filter = Filter<Data>.Term("shorturl", url);
var results = this.Client.Search<Data>(s => s
.Filter(filter)
);
QueryContainer q = new QueryContainer();
q = Query<Data>.Term("shorturl", url);
results = this.Client.Search<Data>(s => s
.Query(q)
);
results = this.Client.Search<Data>(s => s
.Query(f => f.Term(p=> p.ShortUrl, url))
);
我应该注意以下是我正在使用的版本:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Elasticsearch.Net" version="1.3.1" targetFramework="net45" />
<package id="NEST" version="1.3.1" targetFramework="net45" />
<package id="Newtonsoft.Json" version="6.0.1" targetFramework="net45" />
</packages>
找到答案 需要确保字符串设置为“NOT ANALYZED”
[ElasticProperty(Name = "shorturl", IncludeInAll = true,
Index=FieldIndexOption.NotAnalyzed)]
public string ShortUrl { get; set; }
答案 0 :(得分:2)
[ElasticProperty(Name = "shorturl", IncludeInAll = true,
Index=FieldIndexOption.NotAnalyzed)]
public string ShortUrl { get; set; }