【问题标题】:Multi match query with terms lookup searching multiple indices elasticsearch 6.x带有术语查找的多匹配查询搜索多个索引elasticsearch 6.x
【发布时间】:2019-05-21 10:46:59
【问题描述】:

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

请看下面的详细信息

使用的指数

  1. 开发样本搜索
  2. 用户代理搜索

搜索的工作方式如下。

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

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

  3. agentNumber、customerName、fileNumber、documentid 和状态是 索引 dev-sample-search 的一部分。

  4. status 字段被定义为keyword

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

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

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

dev-sample-search 索引数据示例:

{

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

【问题讨论】:

    标签: elasticsearch nest


    【解决方案1】:

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

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

    【讨论】:

    • 感谢@Russ Cam。我的另一个问题是,在查询多个索引时,我们是否应该为每个字段指定索引上下文,如果不指定,ES 是否会在所有索引中查找该字段?
    猜你喜欢
    • 1970-01-01
    • 2014-06-02
    • 2020-06-12
    • 1970-01-01
    • 2018-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-03
    相关资源
    最近更新 更多