如何在弹性搜索上使用查询字符串搜索进行字段查询?

How to do a fields query using query string search on elastic search?

我想转换这个查询:

GET demo-index/_search
{
 "fields": [
 "*"
 ]
}

变成这样的东西:

GET demo-index/_search?fields=*

是否可以在不使用请求的 json 正文的情况下以这种方式或类似的方式进行字段查询?

你可以试试 filter_path :

如果我们有下一个 return:

{
  "took" : 3,
  "timed_out" : false,
  "_shards" : {
    "total" : 3,
    "successful" : 3,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 10000,
      "relation" : "gte"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "demo-index",
        "_type" : "_doc",
        "_id" : "32223223d3e23dd23d2x23",
        "_score" : 1.0,
        "_source" : {
          "username" : "Mike",
          "date" : "2022-04-04"
        }
      }
    ]
  }
}

而我们想要return所有的字段,应该写路径如下:

GET demo-index/_search?filter_path=hits.hits._source.*

如果我们想要像“用户名”这样的具体字段,我们应该把路径写成如下

GET demo-index/_search?filter_path=hits.hits._source.username