How to search via Json in elastic search using spring resttemplate in android

后端 未结 2 420
醉梦人生
醉梦人生 2020-12-06 15:48

Hi i am trying to search data in elastic search using spring RestTemplate. ElasticSearch have user name and password and i want to search via json.

I wrote code for

相关标签:
2条回答
  • 2020-12-06 16:09

    Unlike other Relational Databases, you don't need Spring RestTemplate to query the elastic database. ElasticSearch comes with inbuilt Java API library. You directly use those functions to create your query and get the results.

    Checkout this Link. It has the documentation about how to use the API.

    Elastic Search Java API 5.1

    0 讨论(0)
  • 2020-12-06 16:12

    I would recommend Using the ES Java API as mentioned by Tanay.

    Set up your connection like this

    //Create the ES clien
    org.elasticsearch.client.Client client;
    
    //Setup the connection. Make sure you use port 9300 and not 9200 here.
    client = new PreBuiltTransportClient(Settings.EMPTY)
                        .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), "9300"));
    
    //Interact with your index, for example getting an object by its ID
    GetResponse response = client.prepareGet("index", "type", "id")
        .setOperationThreaded(false)
        .get();
    
    //Close the connection
    client.close();
    
    0 讨论(0)
提交回复
热议问题