Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
720 views
in Technique[技术] by (71.8m points)

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

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 this but i am not getting any result or exception. I am doing this for the first time in my life so sorry if there is some silly mistake in it.

@Override
    protected List<JobPosts> doInBackground(Object[] objects) {
        List list = null;

        try {

            SearchForm searchForms = (SearchForm) objects[0];




            String plainCreds = "******:********";

            final String url = "*******";
            RestTemplate restTemplate = new RestTemplate();
            restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());

            HttpEntity<String> request = new HttpEntity<>(searchJson, headers);
            Log.d("location", "before exchange");
            ResponseEntity<JobPosts[]> response = restTemplate.exchange(url, HttpMethod.GET, request, JobPosts[].class);
            JobPosts[] jobPosts = response.getBody();

            Log.d("location", "after exchange");
            list = Arrays.asList(jobPosts);


        } catch (Exception e) {
            Log.d("location", e.getMessage());
        }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...