布尔 'and' 在 ElasticSearch.Nest 客户端中搜索

Boolean 'and' search within ElasticSearch.Nest client

我有一个弹性搜索查询,它是 return 我认为的 'or' 搜索。弹性搜索Nest客户端是v4.0.30319,弹性搜索服务器是1.6.0版本。 'and' 搜索在索引 'sc' 上。针对相关数据库 table 的等效 sql 语句 运行 "select * from clients where profile like '%business%' and ... profile like '%Helping%' " 将 return 没有记录。我将如何更改以下查询 and/or 代码以执行布尔 'and' 搜索?

query = 'id:("7ee683c2-19eb-45c6-9ca8-985379ce34dd") 
         AND role:("User","OrganizationAdmin","SystemAdmin","follower") 
         AND (  
              sc:("business*") 
              and  sc:("objectives*") 
              and  sc:("memorable*") 
              and  sc:("Keith*") 
              and  sc:("Lawyer*") 
              and  sc:("accountant*") 
              and  sc:("Helping*") )' ;

result = _client.Search<T>(
 t => t.Types(type).Index(_index).Query(
    qt => qt.QueryString(qs => qs.Query(query).OnFields(fields))).Filter(
        x => x.Range(y => y.From(fromDate).To(toDate).OnField(rangeOnField))
    ).SortDescending(orderByField).SortDescending("_score").Skip(skipRecord).Take(pageSize));

我发现 result.ConnectionStatus 包含真正有用的原始弹性搜索查询。使用基本查询,然后手动添加 sc 的布尔条件给出原始搜索条件

    {
      "from": 0,
      "size": 100,
      "sort": {
        "cd": "desc",
        "_score": "desc"
      },
      "query": {
        "query_string": {
          "query": "id:(\"7ee683c2-19eb-45c6-9ca8-985379ce34dd\") AND role:(\"User\",\"OrganizationAdmin\",\"SystemAdmin\",\"follower\") AND ( sc:(\"business*\") AND sc:(\"objectives*\")  AND sc:(\"memorable*\")  AND  sc:(\"Keith*\") AND  sc:(\"Lawyer*\") AND  sc:(\"accountant*\") AND  sc:(\"Helping*\") ) ",
          "fields": [
            "id",
            "sc",
            "role",
            "nm"
          ]
        }
      },
      "filter": {
        "range": {
          "cd": {
            "from": "19160709",
            "to": "21160709"
          }
        }
      }
    }

return 没有结果,所以我猜代码有一些奇怪的地方。

原来需要更改查询。 'and' 需要 'AND'.

这个查询

{
    "from": 0,
    "size": 100,
    "sort": {
        "cd": "desc",
        "_score": "desc"
    },
    "query": {
        "query_string": {
            "query": "id:(\"7ee683c2-19eb-45c6-9ca8-985379ce34dd\") AND role:(\"User\",\"OrganizationAdmin\",\"SystemAdmin\",\"follower\") AND ( sc:(\"business*\") AND sc:(\"objectives*\")  AND sc:(\"memorable*\")  AND  sc:(\"Keith*\") AND  sc:(\"Lawyer*\") AND  sc:(\"accountant*\") AND  sc:(\"Helping*\") ) ",
            "fields": [
                "id",
                "sc",
                "role",
                "nm"
            ]
        }
    },
    "filter": {
        "range": {
            "cd": {
                "from": "19160709",
                "to": "21160709"
            }
        }
    }
}

没有返回任何记录,但是这个查询

{
    "from": 0,
    "size": 100,
    "sort": {
        "cd": "desc",
        "_score": "desc"
    },
    "query": {
        "query_string": {
            "query": "id:(\"7ee683c2-19eb-45c6-9ca8-985379ce34dd\") AND role:(\"User\",\"OrganizationAdmin\",\"SystemAdmin\",\"follower\") AND (   sc:(\"business\")  and sc:(\"objectives\")  and sc:(\"memorable\")  and sc:(\"Keith\")  and sc:(\"Lawyer\")  and sc:(\"accountant\")  and sc:(\"Helping\") ) ",
            "fields": [
                "id",
                "sc",
                "role",
                "nm"
            ]
        }
    },
    "filter": {
        "range": {
            "cd": {
                "from": "19160709",
                "to": "21160709"
            }
        }
    }
} 

未能返回 3 条记录。唯一的区别是字段 'sc'.

括号中 'and' 的大小写