如何通过Json在弹性搜索中使用spring resttemplate在android中搜索 [英] How to search via Json in elastic search using spring resttemplate in android

查看:237
本文介绍了如何通过Json在弹性搜索中使用spring resttemplate在android中搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在使用弹簧RestTemplate搜索弹性搜索中的数据。 ElasticSearch有用户名和密码,我想通过json搜索。

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());
        }


推荐答案

与其他关系数据库不同不需要Spring RestTemplate查询弹性数据库。 ElasticSearch附带内置的Java API库。您直接使用这些功能创建查询并获取结果。

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.

查看此链接。它有关于如何使用API​​的文档。

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

弹性搜索Java API 5.1

这篇关于如何通过Json在弹性搜索中使用spring resttemplate在android中搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆