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

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

问题描述

我正在尝试使用 spring 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.

Elastic搜索 Java API 5.1

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

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