Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.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子句下使用range和match进行查询?_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch - Fatal编程技术网 elasticsearch 如何在must子句下使用range和match进行查询?,elasticsearch,elasticsearch" /> elasticsearch 如何在must子句下使用range和match进行查询?,elasticsearch,elasticsearch" />

elasticsearch 如何在must子句下使用range和match进行查询?

elasticsearch 如何在must子句下使用range和match进行查询?,elasticsearch,elasticsearch,我试图提取过去24小时的数据,给定的值必须与字段匹配。我已经编写了与字段值匹配的查询,并在过去24小时内进行了查询,但我不知道如何组合它们 最近24小时的查询: { "_source": ["instance_name", "@timestamp"], "query": { "range": { "sampletime": { "gte": "now-24h", "lte": "now" } } } } 要匹

我试图提取过去24小时的数据,给定的值必须与字段匹配。我已经编写了与字段值匹配的查询,并在过去24小时内进行了查询,但我不知道如何组合它们

最近24小时的查询:

{
  "_source": ["instance_name", "@timestamp"], 
  "query": {
    "range": {
      "sampletime": {
        "gte": "now-24h",
        "lte": "now"
      }
    }
  }
}
要匹配的查询字段:

{
  "_source": ["instance_name", "@timestamp"], 
  "query": {
    "match": {
      "instance_name": "value_to_search"
    }
  }
}
尝试将两者结合起来:

{
  "_source": ["instance_name", "@timestamp"], 
  "query": {
    "bool": {
      "must": [{
        "match": {
          "instance_name": "value"
        },
        "range": {
          "sampletime": {
            "gte": "now-24h",
            "lte": "now"
            }
          }
      }]
    }
  }
}
有没有办法把这些结合起来?还可以针对同一字段下的多个值


instance_name==x | | instance_name==y | | instance_name==z

您的尝试非常接近。
范围
查询的格式设置稍有偏差

以下是校正后的样本:

{
  "_source": ["instance_name", "@timestamp"], 
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "instance_name": "value"
          }
        },
        {
        "range": {
          "sampletime": {
            "gte": "now-24h",
            "lte": "now"
            }
          }
        }
      ]
    }
  }
}
关于第二个问题,默认情况下,所有匹配查询都将使用
运算符

例如,
字段
将所有点击与
a或b或c
匹配:

{
  "query": {
    "match": {
      "FIELD": "a b c"
    }
  }
}
您可以在中阅读有关匹配查询的完整选项的更多信息