简体   繁体   English

使用条件中的字符串列表进行Elasticsearch查询。 Nest 5.x

[英]Elasticsearch Query using list of strings in criteria. Nest 5.x

I am using Elasticsearch 5.0.1, and I am running my code under .NET 4.5.2. 我正在使用Elasticsearch 5.0.1,并且正在.NET 4.5.2下运行我的代码。 I am using NEST 5.0 rc lib. 我正在使用NEST 5.0 rc lib。

I have a class that contains a list of string. 我有一个包含字符串列表的类。

public List<string> LastPagesViewed { get; set; }

I am mapping that clase using AutoMap like this: 我正在像这样使用AutoMap映射该分类:

.Mappings(m => m.Map<VisitorTest>(map => map.AutoMap()))

What I want to do is to query all the document that contains one or more urls on 'LastPagesViewed' property. 我想做的是查询所有包含“ LastPagesViewed”属性上一个或多个URL的文档。

I am doing a search like this: 我正在这样搜索:

.Query(q => q
.Terms(c => c
    .Name("named_query")
    .Field(p => p.LastPagesViewed)
    .Terms(new List<string> { "url1", "url2" }))

But it is not working. 但这是行不通的。 I also tried to search only part of the url like "google" (if the url is http://www.google.com ) but same result. 我还尝试仅搜索部分网址,例如“ google”(如果该网址为http://www.google.com ),但结果相同。

I tried this with a list of ints (instead of urls) and it is working, so what I am missing here? 我尝试了一个int列表(而不是url),它正在工作,所以我在这里缺少什么?

Finally got it!. 终于明白了! The problem was that I did not take into account the analyzer impact when using term search. 问题是,在使用术语搜索时,我没有考虑分析器的影响。 Once I change the query to use a match it all works as expected. 一旦我将查询更改为使用匹配项,一切将按预期工作。

The new query will be like this: 新查询将如下所示:

.Query(q => q.Match(mq => mq.Field(p => p.LastPagesViewed.First()).Query("http://www.google.com")))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM