Java操作Elasticsearch问题总结

基于SpingBoot

1、集合查询
Set<String> set = new HashSet<>();
QueryBuilders.termsQuery("cityId", set);
//select * from city where cityId in ("hhu-hsh","hus-hihs","his-hshis")
2、查询数据中包含有连接符

如果使用org.springframework.data.elasticsearch
使用了ik导致字段被默认分词,只需要关闭分词即可

/**
*	cityId = "hfhahs-dbabdhau-shdoihaoi-siuhiud"
**/
@Field(analyzer = "whitespace",searchAnalyzer = "whitespace", type = FieldType.Text, fielddata = true)
private String cityId;

你可能感兴趣的:(Java学习笔记,java)