当我对这样的索引执行查询时:
{
"_source":["bar"] , "size":100,
"query": {
"match_all": {}
},
"filter": {
"type" : {
"value" : "foo"
}
}
}
响应包括索引,类型等。但我已经知道了索引和类型,因为我指定了它。这些信息只会膨胀json数据的大小。有没有办法从响应中排除这些?
这就是我得到的:
{
"took": 31,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 364024,
"max_score": 1,
"hits": [
{
"_index": "foo_bar",
"_type": "foo",
"_id": "asdjj123123",
"_score": 1,
"_source": {
"bar": "blablablabla"
}
}
,...
我想要的是这样的,所以没有类型,分数,索引的回复:
{
"took": 31,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 364024,
"max_score": 1,
"hits": [
{
"_id": "asdjj123123",
"_source": {
"bar": "blablablabla"
}
}
,...
答案 0 :(得分:8)
是的,从ES 1.6开始,您可以使用response filtering并使用查询中的filter_path
参数枚举您在响应中所需的内容:
curl -XGET 'localhost:9200/foo_bar/foo/_search?pretty&filter_path=hits.total,hits.max_score,hits.hits._id,hits.hits._source'
答案 1 :(得分:1)
_source
选项可用于实现此目的。
查询JSON且不想使用filter path
时,可以执行以下操作
{
"_source":{
"includes":["field1", "field2"],
"excludes":["_index", "_type", "_score"]
}
}
您只能定义includes
,只能定义excludes
或两者都定义。响应相应地起作用。