c# - SQL IN等同于ElasticSearch

标签 c# .net elasticsearch

我试图弄清楚如何用ElasticSearch做一个SQL IN子句。

下面的查询将起作用,但是当我将其更改为“query”时:[“1589”,“1590”]则无效。我相信它正在对同一字段的这2个值进行“与”运算,并且我希望它在“或”运算中进行“或”运算。

作品

{
  "size": 10,
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "userId": {
              "query": ["1589"]
            }
          }
        }
      ]
    }
  }
}

失败
{
  "size": 10,
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "userId": {
              "query": ["1589", "1590"]
            }
          }
        }
      ]
    }
  }
}

最佳答案

那么下面应该工作-

{
  "size": 10,
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "userId": {
              "query": ["1589"]
            }
          }
        },
        {
          "match": {
            "userId": {
              "query": ["1590"]
            }
          }
        }

      ]
    }
  }
}

记住must必须是AND之类的东西,应该可以单独使用以获得OR之类的东西

关于c# - SQL IN等同于ElasticSearch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34794914/

相关文章:

c# - 从通用 Windows 平台 (UWP) 应用程序向 Azure 通知中心发送通知

.net - C# : How Are Boxed Value Types Handled 中的 Protocol Buffer

c# - 如何取消发布 .Net 应用程序

elasticsearch 处理拼写错误

c# - 序列化从 DynamicObject 类派生的类的实例

c# - 从 PropertyInfo 创建通用列表 <Type>

c# - Azure AD 图 : Secure binary serialization is not supported on this platform

c# - 多写者单读者并发模型的最有效锁?

elasticsearch - 如果确切的单词用作文本,elasticsearch不会建议任何内容?

spring - 从ElasticSearch取回数据