postForObject Solr查询

时间:2019-05-10 15:30:47

标签: spring-boot kotlin solr

我正在尝试运行Solr搜索,并不断收到400个错误的请求。

从我们的一个Linux机器中,我可以运行它来搜索Solr:

curl "http://address.com:port/solr/core_name/select?indent=on&q=column:first_name,last_name"

这是我为尝试运行此查询而写的。

data class RoutingRequest(val columnNames: List<String>)

fun callSolrResponse(routingRequest: RoutingRequest): SolrResponse? {

        val headers = HttpHeaders()
        headers.contentType = MediaType.TEXT_PLAIN

        val request = HttpEntity(routingRequest.columnNames.joinToString(separator =","), headers)

        return restTemplate.postForObject(
                "http://address.com:port/solr/core_name/select?indent=on&q=column:",
                request,
                SolrResponse::class.java
        )
    }

如果我放弃了select?indent=on&q=column:并将其添加到请求中,则找不到404。

我应该将请求发布为JSON对象吗?

将其更改为get请求并使用整个URL可行,如果URL太大,我会遇到问题吗? idk如何使其与发布请求一起使用:

 fun callSolrResponse(routingRequest: RoutingRequest): SolrResponse? {

        val headers = HttpHeaders()
        headers.contentType = MediaType.TEXT_PLAIN

        return restTemplate.getForObject(
                "http://address.com:port/solr/core_name/select?indent=on&q=column:".plus(routingRequest.columnNames.joinToString(separator =",")),
                SolrResponse::class.java
        )

0 个答案:

没有答案