【发布时间】:2020-03-14 02:55:31
【问题描述】:
我刚刚开始使用带有 spring 的 elasticsearch,这两种技术对我来说都是全新的。我已经使用 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>{}
控制器:
@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 得到的输出如下:
[{},{},{},{},....]
【问题讨论】:
-
也许你的 _source 是假的?
-
这是配置文件的选项吗,因为我没有使用任何名为_source的字段,_source的默认选项是否为false?
标签: spring spring-boot elasticsearch spring-data logstash