Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
<img src="//i.stack.imgur.com/RUiNP.png" height="16" width="18" alt="" class="sponsor tag img">elasticsearch 弹性搜索-使用must或must not查询处理条件_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch - Fatal编程技术网 elasticsearch 弹性搜索-使用must或must not查询处理条件,elasticsearch,elasticsearch" /> elasticsearch 弹性搜索-使用must或must not查询处理条件,elasticsearch,elasticsearch" />

elasticsearch 弹性搜索-使用must或must not查询处理条件

elasticsearch 弹性搜索-使用must或must not查询处理条件,elasticsearch,elasticsearch,我们有一个要求,如果有newId,那么我们必须在今天之前获取数据 如果数据中没有newId字段,那么我们必须在到期日+2个月之前获取数据。 我试图在下面查询,但结果并没有达到预期 { "id":"234", "startDate":"23/07/2020", "endDate":"24/09/20202", "newId":

我们有一个要求,如果有newId,那么我们必须在今天之前获取数据 如果数据中没有newId字段,那么我们必须在到期日+2个月之前获取数据。 我试图在下面查询,但结果并没有达到预期

 {
    "id":"234",
    "startDate":"23/07/2020",
    "endDate":"24/09/20202",
    "newId":"2345"
    },
   {
    "id":"234",
    "startDate":"23/07/2020",
    "endDate":"24/09/20202",
    "newId":null
    },
{
    "id":"235",
    "startDate":"23/07/2020",
    "endDate":"24/06/2020",
    "newId":"2345"
    },
我正在尝试的疑问

预期结果

{ “id”:“234”, “起始日期”:“2020年7月23日”, “结束日期”:“20202年9月24日”, “newId”:“2345” }, { “id”:“234”, “起始日期”:“2020年7月23日”, “结束日期”:“20202年9月24日”, “newId”:空
},

好的开始!您的查询几乎是正确的,但还需要一些调整,即使用
应该
而不是
必须
,因为这两个子查询永远不会同时为真:

{
  "query": {
    "bool": {
      "minimum_should_match": 1,
      "should": [
        {
          "bool": {
            "must": [
              {
                "exists": {
                  "field": "newId"
                }
              },
              {
                "range": {
                  "endDate": {
                    "gte": "now/d"
                  }
                }
              }
            ]
          }
        },
        {
          "bool": {
            "must": [
              {
                "range": {
                  "endDate": {
                    "gte": "now-2M"
                  }
                }
              },
              {
                "bool": {
                  "must_not": [
                    {
                      "exists": {
                        "field": "newId"
                      }
                    }
                  ]
                }
              }
            ]
          }
        }
      ]
    }
  }
}

是的,它起作用了。谢谢你的帮助。我创建了一个新的帖子。你能帮忙吗?太棒了,很高兴能帮上忙!
{
  "query": {
    "bool": {
      "minimum_should_match": 1,
      "should": [
        {
          "bool": {
            "must": [
              {
                "exists": {
                  "field": "newId"
                }
              },
              {
                "range": {
                  "endDate": {
                    "gte": "now/d"
                  }
                }
              }
            ]
          }
        },
        {
          "bool": {
            "must": [
              {
                "range": {
                  "endDate": {
                    "gte": "now-2M"
                  }
                }
              },
              {
                "bool": {
                  "must_not": [
                    {
                      "exists": {
                        "field": "newId"
                      }
                    }
                  ]
                }
              }
            ]
          }
        }
      ]
    }
  }
}