我正在尝试将elasticsearch与Android应用程序集成。
我需要获取 jsonobject 并打印出每个 id 的详细信息。首先,我需要尝试编写Java类。
我可以只使用 json API 还是有一个更容易的弹性搜索 API。
网址: http://www.dummy.com:9200/contacts/index/_search
{
"took": 10,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 1.0,
"hits": [
{
"_index": "contacts",
"_type": "index",
"_id": "2",
"_score": 1.0,
"_source": {
"id": "c201",
"name": "Johnny Depp",
"email": "johnny_depp@gmail.com",
"address": "xx-xx-xxxx,x - street, x - country",
"gender": "male",
"phone": {
"mobile": "+91 0000000000",
"home": "00 000000",
"office": "00 000000"
}
}
},
{
"_index": "contacts",
"_type": "index",
"_id": "1",
"_score": 1.0,
"_source": {
"id": "c200",
"name": "Ravi Tamada",
"email": "ravi@gmail.com",
"address": "xx-xx-xxxx,x - street, x - country",
"gender": "male",
"phone": {
"mobile": "+91 0000000000",
"home": "00 000000",
"office": "00 000000"
}
}
}
]
}
}
有几种方法可以克隆JSON对象..手动使其像字符串一样,使用MAP。是的,ES中有一个帮助程序类是XContentBuilder.以获取有关该@refer的更多信息。
根据我的考虑,最好使用任何JSON API来创建有效的对象并且易于使用。