嵌套多匹配查询,带术语查找搜索多个索引elasticsearch 6.x

r1zk6ea1  于 2021-06-14  发布在  ElasticSearch
关注(0)|答案(1)|浏览(343)

总之,我正在构建一个nest6.x查询,它采用serach术语并在不同的索引中查看不同的字段。这是一个我到目前为止,但没有返回任何结果,我期待。
请看下面的细节
使用的索引
开发人员示例搜索
用户代理搜索
搜索的工作方式如下。
根据字段agentnumber、customername、filenumber、documentid(这些都是分析过的文件)搜索查询字段(27921093)中的值。
搜索应将文档限制为用户指定的代理编号sampleuser@gmail.com 已访问(用户代理搜索的示例数据)添加到下面。
agentnumber、customername、filenumber、documentid和status是index dev示例搜索的一部分。
状态字段定义为关键字。
用户代理搜索索引中的字段都是关键字
示例用户代理搜索索引数据:

{
              "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"
                        }
                      }
                    }
                  ]
                }
              }
            ]
          }
        }
      ]
    }
  }
}
hgncfbus

hgncfbus1#

我看到一些你可能想看的东西:
terms 查找查询, "user": "sampleuser@gmail.com", 应该是 "id": "sampleuser@gmail.com", .
如果至少有一个 should 合同条款 filter 子句应匹配,集合 "minimum_should_match" : 1bool 包含 should 条款

相关问题