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": "[email protected]",
          "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": "[email protected]",
          "address": "xx-xx-xxxx,x - street, x - country",
          "gender": "male",
          "phone": {
            "mobile": "+91 0000000000",
            "home": "00 000000",
            "office": "00 000000"
          }
        }
      }
    ]
  }
}
2
  • 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 Commented Apr 2, 2014 at 13:19
  • I feel the json object returned by elasticsearch is different from the normal json response string. Could you please suggest Commented Apr 2, 2014 at 13:24

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

2 Comments

this is link only answer with dead links, this is why link only answers suck
@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..

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.