多匹配查询与术语查找搜索多个索引 elasticsearch 6.x

Multi match query with terms lookup searching multiple indices elasticsearch 6.x

全部, 我正在构建一个 NEST 6.x 查询,该查询采用搜索词并在不同索引的不同字段中查找。 这是我目前得到的结果,但没有返回任何我期望的结果。

详情请见下方

使用的索引

  1. 开发示例搜索
  2. 用户代理搜索

搜索的工作方式如下。

  1. 查询字段中的值(27921093)是针对 fields agentNumber, customerName, fileNumber, documentid(这些都是 分析的文件)。

  2. 搜索应将文档限制为 agentNumbers 个用户 sampleuser@gmail.com 有权访问(示例数据 user-agents-search) 添加在下面。

  3. agentNumber, customerName, fileNumber, documentid and status 是 部分索引 dev-sample-search.

  4. status 字段定义为 关键字

  5. user-agents-search索引中的字段都是keywords

    示例用户代理搜索索引数据:

     {
                  "id": "sampleuser@gmail.com"",
                  "user": "sampleuser@gmail.com"",
                  "agentNumber": [
                    "123.456.789",
                    "1011.12.13.14"
                  ]
        }
    

样本开发样本搜索索引数据:

{

          "agentNumber": "123.456.789",          
          "customerName": "Bank of america",
          "fileNumber":"test_file_1123",
          "documentid":"1234456789"
 }

GET dev-sample-search/_search
{
  "from": 0,
  "size": 10,
  "query": {
    "bool": {
      "must": [
        {
          "multi_match": {
            "type": "best_fields",
            "query": "27921093",
            "operator": "and",
            "fields": [
              "agentNumber",
              "customerName",
              "fileNumber",              
              "documentid^10"
            ]
          }
        }
      ],
      "filter": [
        {
          "bool": {
            "must": [
              {
                "terms": {
                  "agentNumber": {
                    "index": "user-agents-search",
                    "type": "_doc",
                    "user": "sampleuser@gmail.com",
                    "path": "agentNumber"
                  }
                }
              },
              {
                "bool": {
                  "must_not": [
                    {
                      "terms": {
                        "status": {
                          "value": "pending"
                        }
                      }
                    },
                    {
                      "term": {
                        "status": {
                          "value": "cancelled"
                        }
                      }
                    },
                    {
                      "term": {
                        "status": {
                          "value": "app cancelled"
                        }
                      }
                    }
                  ],
                  "should": [
                    {
                      "term": {
                        "status": {
                          "value": "active"
                        }
                      }
                    },
                    {
                      "term": {
                        "status": {
                          "value": "terminated"
                        }
                      }
                    }
                  ]
                }
              }
            ]
          }
        }
      ]
    }
  }
}

我看到一些你可能想看的东西:

  1. terms 查找查询中,"user": "sampleuser@gmail.com", 应该是 "id": "sampleuser@gmail.com",
  2. 如果 filter 子句中至少有一个 should 子句匹配,则在包含 should 子句的 bool 查询上设置 "minimum_should_match" : 1