返回结果属性:
took:查询结果花费的时间(ms)
timed_out:是否超时
_shards:分片信息:{total:总共的分片数,successful:成功查询的分片数:skipped跳过查询的分片数,failed:查询失败的分片数}
hits:返回结果信息:{
total:返回的结果总数,
max_score:最大文档分数,hits:返回真实的结果:{
_index:索引,
_type:类型,
_id:id,
_score:文档分数,
_source:文档的fields
}
}
_score:
称为文档分数(搜索结果中的_score字段)。分数是一个数字值,它是文档与我们指定的搜索查询匹配程度的相对度量。分数越高,文档越相关,分数越低,文档的相关性越低。
response filtering(响应过滤)
所有REST API接受一个filter_path参数,可以用来减少elasticsearch返回的响应。 此参数以逗号分隔的以点表示法表示的过滤器列表:
例如:1.
curl -XGET 'localhost:9200/_search?q=elasticsearch&filter_path=took,hits.hits._id,hits.hits._score&pretty'
Responds:
{
"took" : 3,
"hits" : {
"hits" : [
{
"_id" : "0",
"_score" : 1.6375021
}
]
}
}
2.它还支持*通配符匹配任何字段或字段名称的一部分:
curl -XGET 'localhost:9200/_cluster/state?filter_path=metadata.indices.*.stat*&pretty'
Responds
{
"metadata" : {
"indices" : {
"twitter": {"state": "open"}
}
}
}
3.并且**通配符可用于包括不知道确切路径的fields。
curl -XGET 'localhost:9200/_cluster/state?filter_path=routing_table.indices.**.state&pretty'
Responds:
{
"routing_table": {
"indices": {
"twitter": {
"shards": {
"0": [{"state": "STARTED"}, {"state": "UNASSIGNED"}],
"1": [{"state": "STARTED"}, {"state": "UNASSIGNED"}],
"2": [{"state": "STARTED"}, {"state": "UNASSIGNED"}],
"3": [{"state": "STARTED"}, {"state": "UNASSIGNED"}],
"4": [{"state": "STARTED"}, {"state": "UNASSIGNED"}]
}
}
}
}
}
4.你也可以通过字符“-”作为前缀去排除一个或多个fields:
GET /_count?filter_path=-_shards
Responds:
{
"count" : 5
}
5.为了更多的控制,包含和排他的过滤器可以在同一表达式中组合。 在这种情况下,将首先应用排他过滤器,并使用包含的过滤器再次对结果进行过滤:
curl -XGET 'localhost:9200/_cluster/state?filter_path=metadata.indices.*.state,-metadata.indices.logstash-*&pretty'
Responds:
{
"metadata" : {
"indices" : {
"index-1" : {"state" : "open"},
"index-2" : {"state" : "open"},
"index-3" : {"state" : "open"}
}
}
}
Keyed Response
将“key”设置为true("keyed": true)可将唯一的字符串键与每个存储桶相关联,并将范围作为散列值而不是数组返回:
1.
curl -XPOST 'localhost:9200/sales/_search?size=0&pretty' -H 'Content-Type: application/json' -d'
{
"aggs": {
"range": {
"date_range": {
"field": "date",
"format": "MM-yyy",
"ranges": [
{ "to": "now-10M/M" },
{ "from": "now-10M/M" }
],
"keyed": true
}
}
}
}
'
Response:
{
...
"aggregations": {
"range": {
"buckets": {
"*-10-2015": {
"to": 1.4436576E12,
"to_as_string": "10-2015",
"doc_count": 7
},
"10-2015-*": {
"from": 1.4436576E12,
"from_as_string": "10-2015",
"doc_count": 0
}
}
}
}
}
2.也可以自定义每个范围的键:
POST /sales/_search?size=0
{
"aggs": {
"range": {
"date_range": {
"field": "date",
"format": "MM-yyy",
"ranges": [
{ "from": "01-2015", "to": "03-2015", "key": "quarter_01" },
{ "from": "03-2015", "to": "06-2015", "key": "quarter_02" }
],
"keyed": true
}
}
}
}
Response:
{
...
"aggregations": {
"range": {
"buckets": {
"quarter_01": {
"from": 1.4200704E12,
"from_as_string": "01-2015",
"to": 1.425168E12,
"to_as_string": "03-2015",
"doc_count": 5
},
"quarter_02": {
"from": 1.425168E12,
"from_as_string": "03-2015",
"to": 1.4331168E12,
"to_as_string": "06-2015",
"doc_count": 2
}
}
}
}
}

2715

被折叠的 条评论
为什么被折叠?



