我的项目中使用的技术(Spring mvc,elasticsearch,rest api),问题是,我的弹性搜索jdbc导入器无法像运算符一样运行sql,iam获取空数据,所以请任何人帮助我。< / p>
package com.technoshinelabs.ulearn.rest.controller;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController;
import com.technoshinelabs.ulearn.api.elasticsearch.repository.AutocompleteRepository; import com.technoshinelabs.ulearn.controller.BaseController; import com.technoshinelabs.ulearn.rest.entity.ResponseEntity; import com.technoshinelabs.ulearn.rest.util.RestStatus; import com.technoshinelabs.ulearn.util.ControllerUriConstant;
@RestController @RequestMapping(value = ControllerUriConstant.rest_autocomplete) public class RestAutocompleteController extends BaseController {
@Autowired AutocompleteRepository autoCompleteRepository;
/** * * @param autoComplete * @return */ @RequestMapping(value = ControllerUriConstant.rest_autocompletesearch, method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity getOverLayWords(@RequestParam("q") String name) { System.out.println("check search value" + " " + name); return getResponseEntity(autoCompleteRepository.findByName(name), RestStatus.OK.getCode(), RestStatus.OK.getText()); } }
package com.technoshinelabs.ulearn.api.elasticsearch.repository;
import java.util.List;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import com.technoshinelabs.ulearn.api.elasticsearch.entities.Autocomplete;
public interface AutocompleteRepository extends ElasticsearchRepository<Autocomplete, String>{
public List<Autocomplete> findByName(String name); }
@echo off
set DIR=%~dp0 set LIB=%DIR%..\lib\* set BIN=%DIR%..\bin
REM ??? echo {^
"type" : "jdbc",^
"jdbc" : {^
"url" : "jdbc:mysql://localhost:3306/ulearn_app",^
"user" : "root",^
"password" : "root",^
"sql" : "Select id as _id, id, name from course where name like '%name%'",^
"treat_binary_as_string" : true,^
"elasticsearch" : {^
"cluster" : "elasticsearch",^
"host" : "localhost",^
"port" : 9300^
},^
"index" : "ind_autocomplete"^
}^ }^ | "%JAVA_HOME%\bin\java" -cp "%LIB%" -Dlog4j.configurationFile="%BIN%\log4j2.xml" "org.xbib.tools.Runner" "org.xbib.tools.JDBCImporter"
答案 0 :(得分:0)
至少有两种方法可以做到这一点。我使用第二个,因为我不需要在jdbc中使用'to'更改并将\'更改为'以在sql工具中测试查询。
\' for each '
OR ..将查询作为视图存储在数据库中。然后使用\'
调用视图而不是sql在您的数据库中:
CREATE VIEW your_jdbc_view AS
Select id as _id, id, name from course where name like '%name%';
将elasticsearch文件中的行更改为:
“sql”:"Select * from your_jdbc_view",