Jlastic的弹性搜索,Spring

有人能举例说明在jHipsterSpring-boot中使用Elasticsearch吗?

我已经使用jHipster生成了实体。 有占位符的输入:查询!

/** * SEARCH /_search/samples/:query -> search for the sample corresponding * to the query. */ @RequestMapping(value = "/_search/samples/{query}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @Timed public List search(@PathVariable String query) { return StreamSupport .stream(sampleSearchRepository.search(queryString(query)).spliterator(), false) .collect(Collectors.toList()); } 

如何使用elasticsearch?

这里有一些我在生成实体中找到的脚本!

我已经尝试过放置Objectq = field:value弹性格式的数组,并且总是得到空数组

抱歉英语不好!

好吧,你的索引似乎是空的。 如果以编程方式添加实体(即不是从界面添加),请务必将它们保存在搜索存储库中。

示例:

 Sample sample = new Sample(); sample.setName("bar"); sample = sampleRepository.save(sample); sampleSearchRepository.save(sample); 

您需要重新生成样本以获取Hibernate生成的id在elasticsearch中正确索引。

更新2016年2月10日

现在有一个JHipster模块来重新索引elasticsearch存储库 。

您应该通过用“sample”实体中要搜索的字符串替换placeolder来对URL进行GET调用。

您可以使用rest客户端(例如,firefox的restclient插件)或curl来测试呼叫。 url应该是这样的:

 http://localhost:8080/_search/samples/queryString 

您将以json格式获得结果。

如果您需要自定义默认搜索行为,请检查Spring上的Elasticsearch文档:

http://docs.spring.io/spring-data/elasticsearch/docs/1.0.5.RELEASE/reference/html/elasticsearch.repositories.html