1

I am trying to integrate elasticsearch with android app.

I need to get the jsonobject and print out the details for each id. First I need to try writing java class.

Can I just use json api or is there a elasticsearch api which is easier.

url: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"
          }
        }
      }
    ]
  }
}
Saeed Zhiany
  • 2,051
  • 9
  • 30
  • 41
user414977
  • 265
  • 3
  • 8
  • 24
  • I have managed to get the json object from url. But now to iterate through each of the contacts i am getting org.json.JSONObject cannot be cast to org.json.JSONArray. @BlackPOP – user414977 Apr 02 '14 at 13:19
  • I feel the json object returned by elasticsearch is different from the normal json response string. Could you please suggest – user414977 Apr 02 '14 at 13:24

1 Answers1

0

There is several way to craete JSON object.. make it manually like string,use MAP.And yes there is an helper class in ES that is XContentBuilder .for more info about that @refer.

As per my considerations its better use any JSON API to create a valid object and easy to use.refer

BlackPOP
  • 5,657
  • 2
  • 33
  • 49
  • this is link only answer with dead links, this is why link only answers suck –  Feb 18 '16 at 19:18
  • @JarrodRoberson Answer not only have link, it also mention that you can use Any json builder, Map and XContentBuilder provided by Elasticsearch. Links are for reference only.. – BlackPOP Feb 19 '16 at 04:59