[英]Querying ElasticSearch with C# Nest
有一個ElasticSearch索引,其中潛在的點擊量是這樣構建的:
id: number,
source: string,
type: string,
organization: {
main: [string],
support: [string]
},
title: {
main: [string],
sub: [string]
}
我的問題是我無法搜索[]中的元素。
這樣做沒問題:
var searchResults = client.Search<Document>(s => s
.Index(****)
.Type(****)
.MatchAll()
.Query(q =>
q.Term(p => p.source, "some source name")
))
但這不起作用:
var searchResults = client.Search<Document>(s => s
.Index(****)
.Type(****)
.MatchAll()
.Query(q =>
q.Term(p => p.organization.main[0], "some organization name")
))
我也嘗試過此版本,但它也不起作用:
var searchResults = client.Search<Document>(s => s
.Index(****)
.Type(****)
.MatchAll()
.Query(q =>
q.Term(p => p.organization.main, "some organization name")
))
誰能發現問題所在?
您可以使用LINQ的.First()
擴展方法來引用Elasticsearch中的"organization.main"
字段
var searchResults = client.Search<Document>(s => s
.Index(****)
.Type(****)
.MatchAll()
.Query(q =>
q.Term(p => p.organization.main.First(), "some organization name")
)
);
請記住,您的查詢是在此處對整個數組進行操作,而不是organization.main
的第一項,因為這可能暗示.First()
的用法。 數組被索引為無序的多值字段。 但是,它們在_source
返回了順序。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.