【问题标题】:Elastic match for dictionary with dictionary using NEST使用 NEST 的字典与字典的弹性匹配
【发布时间】:2017-08-10 19:06:00
【问题描述】:

早上好,我正在学习如何查询弹性,但我有一个无法找到解决方案的场景,我在弹性上存储了一个 Dictionary<Guid, List<int>>

"myStoredDictionary": {
    "guidA": [14],
    "guidB": [16,17],
    "guidC": [30,31]}

我想用其他结构相同的字典来匹配结果:

这些应该匹配:

"mySearchDictionary1": {
    "guidA": [14,15],
    "guidB": [16],
    "guidC": [30]}

"mySearchDictionary2": {
    "guidA": [14],
    "guidB": [16]}

"mySearchDictionary3": {
    "guidA": [14,15],
    "guidX": [0]
}

所以基本上逻辑是:对于两个字典上存在的每个键,存储的字典应该至少具有搜索列表中的 1 个整数。

有人可以给我一些关于我应该如何处理这个问题的提示吗?谢谢!

【问题讨论】:

  • 所以你有解决方案?

标签: elasticsearch nest


【解决方案1】:

我通过将所有整数存储为一个简单的数组来解决这个问题,忽略了 guid:

"values": [4,14,17,30]

然后使用 must 和每个 guid 的术语就可以了:

{
    "query": {
        "bool": {
            "must": [
                { "terms": { "values": [4,41,42,43] } },
                { "terms": { "values": [14,141,142,143] } },
                { "terms": { "values": [17,171,172,173] } }
            ]
        }
    }
}

因此,如果 terms 数组中的至少一个条目在 values 列表中,则为匹配项。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-10-14
    • 1970-01-01
    • 2016-08-08
    • 1970-01-01
    • 2021-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多