gpt4 book ai didi

java - Jhipster、Spring 上的 Elasticsearch

转载 作者:行者123 更新时间:2023-11-30 06:13:48 25 4
gpt4 key购买 nike

谁能给我在 jHipsterSpring-boot 中使用 Elasticsearch 的例子?

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

/**
* 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<Sample> search(@PathVariable String query) {
return StreamSupport
.stream(sampleSearchRepository.search(queryString(query)).spliterator(), false)
.collect(Collectors.toList());
}

如何使用elasticsearch?

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

我已经尝试放置对象q=field:value具有弹性格​​式的数组,但总是空数组.

抱歉英语不好!

最佳答案

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

示例:

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

您需要重新影响示例以使 Hibernate 生成的 id 在 elasticsearch 中正确索引。

2016 年 10 月 2 日更新

现在有一个 JHipster module to reindex elasticsearch repositories .

关于java - Jhipster、Spring 上的 Elasticsearch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31400746/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com