【发布时间】:2017-01-30 20:08:21
【问题描述】:
我在应用程序中使用 Elasticsearch.Net 和 NEST,并且在基于嵌套对象 ID 进行搜索时无法访问 Elasticsearh 索引中的文档。数据结构为 invoice -> lineItems -> rowItems。我想根据这些 rowItems Id 进行搜索。索引的(简化)映射为:
"invoice": {
"properties": {
"lineItems": {
"properties": {
"accountId": {
"index": "not_analyzed",
"type": "string"
},
"listItems": {
"properties": {
"itemName": {
"analyzer": "str_index_analyzer",
"term_vector": "with_positions_offsets",
"type": "string",
"fields": {
"raw": {
"analyzer": "str_search_analyzer",
"type": "string"
}
}
},
"listItemID": {
"index": "not_analyzed",
"type": "string"
}
}
}
}
}
}
}
当我在其中一个嵌套对象的 chrome 中进行感觉搜索时,我可以成功检索它:
POST /_search
{
"query": {
"bool": {
"should": [
{"match": {
"lineItems.rowItems.rowItemID" : "23f2157f-eb21-400d-b3a1-a61cf1451262"
}}
]
}
}
}
返回文档类型发票及其所有详细信息。
我一直在尝试使用 NEST 执行此操作的代码,但到目前为止都失败了。我有一个 rowItemIds 列表,我想获取与这些 ID 完全匹配的所有发票文档。这是我目前拥有的:
var result = Execute(client => client.Search<Invoice>(s => s
.Aggregations(a => a
.Nested("my_nested_agg", n => n
.Path("lineItems")
.Aggregations(aa => aa
.Filter("my_avg_agg", avg => avg
.Field(p => searchIds.Contains(p.LineItems.First().RowItems.First().TrackingItemID))
)
)
)
)
));
其中 searchIds 是我正在搜索的 rowItemIds 列表。上面的代码是完全错误的,我不熟悉如何做到这一点的语法。任何帮助将不胜感激。
【问题讨论】:
-
我在这里注意到:stackoverflow.com/questions/29346935/… 进行嵌套搜索需要嵌套关键字,例如:“type”:“nested” 是否可以在没有这个的情况下搜索这些 Id(我没有有)。此外,由于系统存在延迟,目前无法选择整个重新索引。
标签: c# nested nest elasticsearch-net