ElasticSearch的条目命中

时间:2015-11-26 08:01:30

标签: elasticsearch

我正在通过

执行ElasticSearch查询
curl -XGET 'http://localhost:9200/_search?pretty' -d '{\"_source\":[\"data.js_event\", \"data.timestamp\",\"data.uid\",\"data.element\"],\"query\":{\"match\":{\"event\":\"first_time_user_event\"}}}'

我只对_source的输出感兴趣,但检索会导致类似

的内容
{"took" : 46,
  "timed_out" : false,
  "_shards" : {
    "total" : 71,
    "successful" : 71,
    "failed" : 0
  },
  "hits" : {
    "total" : 2062326,
    "max_score" : 4.8918204,
    "hits" : [ {
      "_index" : "logstash-2015.11.22",
      "_type" : "fluentd",
      "_id" : "AVEv_blDT1yShMIEDDmv",
      "_score" : 4.8918204,
      "_source":{"data":{"js_event":"leave_page","timestamp":"2015-11-22T16:18:47.088Z","uid":"l4Eys1T/rAETpysn7E/Jog==","element":"body"}}
    }, {
      "_index" : "logstash-2015.11.21",
      "_type" : "fluentd",
      "_id" : "AVEnZa5nT1yShMIEDDW8",
      "_score" : 4.0081544,
      "_source":{"data":{"js_event":"hover","timestamp":"2015-11-21T00:15:15.097Z","uid":"E/4Fdl5uETvhQeX/FZIWfQ==","element":"infographic-new-format-selector"}}
    },
...

有没有办法摆脱_index_type_id_score?原因是查询是在远程服务器上执行的,我想限制下载数据的大小。

感谢。

1 个答案:

答案 0 :(得分:0)

是的,你可以通过在响应中指定你想要的内容(即filter_path=hits.hits._source)来使用response filtering(仅适用于ES 1.7),ES会为你过滤掉它:

curl -XGET 'http://localhost:9200/_search?filter_path=hits.hits._source&pretty' -d '{\"_source\":[\"data.js_event\", \"data.timestamp\",\"data.uid\",\"data.element\"],\"query\":{\"match\":{\"event\":\"first_time_user_event\"}}}'