我们来看一个在Elasticsearch website上找到的简单查询示例:
GET /twitter/_search
{
"query" : {
"term" : { "user" : "kimchy" }
}
}
这将返回以下结果:
{
"took": 1,
"timed_out": false,
"_shards":{
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits":{
"total" : 1,
"max_score": 1.3862944,
"hits" : [
{
"_index" : "twitter",
"_type" : "_doc",
"_id" : "0",
"_score": 1.3862944,
"_source" : {
"user" : "kimchy",
"message": "trying out Elasticsearch",
"date" : "2009-11-15T14:12:12",
"likes" : 0
}
}
]
}
}
结果数据的对象属性是否始终相同,然后我可以通过执行_source
来访问response.hits.hits._source
数据。或者,我是否需要始终验证嵌套对象的每个属性是否存在:
if(response.hits && response.hits.hits && response.hits.hits._source) {
//Do something
}
此问题还涉及过滤器,聚合等。
有什么想法吗?