【发布时间】:2017-01-29 22:27:47
【问题描述】:
我的项目中使用的技术(Spring mvc,elasticsearch,rest api),问题是,我的弹性搜索 jdbc 导入器无法运行类似操作符的 sql,我正在获取空数据,所以请任何人帮助我。
控制器
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); }
AutoComplete.bat
@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"
【问题讨论】:
-
请格式化您的代码...
标签: java spring-mvc elasticsearch