我刚刚开始使用 elasticsearch with spring,这两种技术对我来说都是全新的。我已经使用 logstash 将数据上传到 elasticseach 索引,我可以使用 kebana 成功搜索它。但是,当我尝试使用 spring 从索引返回到网页时,它只返回空的 json 对象,但返回适量的空对象。是我上传的数据不正确还是我的代码有问题?我不明白为什么会这样,如果能得到任何帮助,我将不胜感激。您可以在下面找到一些代码。
类型代码:
@Document(indexName="usmgbg_index", type="usmgbg_type")
public class Usmgbg {
@Id
private String ID;
private String Source, Name, Profession, Country, FileName, LastModified, OwnerID;
}
存储库:
@Repository
public interface UsmgbgRepository extends ElasticsearchRepository<Usmgbg, String>{}
Controller :
@RestController
public class UsmgbgController {
@Autowired
private UsmgbgRepository repository;
@GetMapping("usmgbg/findall")
public List<Usmgbg> findAllCustomers() {
List<Usmgbg> items = new ArrayList<>();
repository.findAll().forEach(items::add);
return items;
}
}
我从 findAllCustomers 得到的输出看起来像:
[{},{},{},{},....]
最佳答案
我意识到这是一个老问题,但我遇到了同样的问题(可能出于不同的原因),我通过在模型中添加 getter 和 setter 解决了这个问题。
关于spring - Elasticsearch 返回空的 json 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58919632/