我有三个tables.Their结构,比如-
public class RcItem{
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "rcItem")
@JsonManagedReference
private Set<RcItemRegulation> rcItemRegulations = new HashSet<>();
}
public class RcItemRegulation{
@ManyToOne
@JoinColumn(name = "rc_item_id")
@Field(type = FieldType.Nested, index = FieldIndex.analyzed, analyzer = "lowercase_keyword", store = true)
@JsonBackReference
private RcItem rcItem;
@ManyToOne
@JoinColumn(name = "rgltn_id")
@Field(type = FieldType.Nested, index = FieldIndex.analyzed, analyzer = "lowercase_keyword", store = true)
private Regulation regulation;
}
public class Regulation{
@OneToMany(cascade = CascadeType.ALL, mappedBy = "regulation")
@JsonManagedReference
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
private Set<RcItemRegulation> rcItemRegulations = new HashSet<>();
@Column(name = "rgltn_full_name")
@Field(type = FieldType.String, index = FieldIndex.analyzed, analyzer = "lowercase_keyword", store = true)
private String rgltnFullName;
}我的数据结构中的上述数据索引如下-
"rcItemRegulations": [
{
"id": 1,
"rcItemRgltnType": "primary",
"regulation": {
"rgltnFullName": "17 ABC § 1.12(f)(5)(i)(B)"
}
}]为此,我尝试使用弹性搜索查询-
{"query":{
"bool" : {
"must" : {
"bool" : {
"must" : [ {
"term" : {
"rcItemRegulations.rcItemRgltnType" : "primary"
}
}, {
"term" : {
"rcItemRegulations.regulation.rgltnFullName" : "17 ABC § 1.12(f)(5)(i)(B)"
}
} ]
}
}
}
}
}这给了我空白结果数组,即使这是exist.Please,也可以帮助我从elastic search中获取数据。
发布于 2017-05-16 19:59:24
我低头看着你的问题。我有两个建议给你。
First
因为rcItemRegulations是一个对象数组,而您试图根据rcItemRegulations中的值进行搜索。因此,我建议您将它们映射为嵌套数据类型。您可以使用以下映射。另外,由于您正在进行精确值匹配,我添加了一个关键字分析器,它将在倒排索引中保留相同的精确值。
映射
{
"settings": {
"analysis": {
"analyzer": {
"index_analyzer_v1": {
"tokenizer": "keyword",
"filter": ["lowercase"]
}
}
}
},
"mappings": {
"type_1": {
"properties": {
"rcItemRegulations": {
"type": "nested",
"properties": {
"regulation": {
"type": "object",
"properties": {
"rgltnFullName": {
"type": "text",
"analyzer": "index_analyzer_v1"
}
}
}
}
}
}
}
}
}其次,,您还需要更改查询,因为您这次是在嵌套数据类型上查询。您必须使用nested_query
{
"query": {
"bool": {
"must": [{
"nested": {
"path": "rcItemRegulations",
"query": {
"bool": {
"must": [{
"term": {
"rcItemRegulations.rcItemRgltnType": "primary"
}
}, {
"term": {
"rcItemRegulations.regulation.rgltnFullName": "17 abc § 1.12(f)(5)(i)(b)"
}
}]
}
}
}
}]
}
}
}注意:搜索查询中的所有文本均为小写。
https://stackoverflow.com/questions/44000119
复制相似问题