【发布时间】:2019-09-27 18:34:55
【问题描述】:
我正在尝试对嵌套对象应用多个过滤器,并且我只想返回在单个对象中而不是来自多个对象中具有所有匹配的文档。
弹性搜索中的数据
D1 document
"fields":[
{
"field_name": "test",
"field_value": "test",
"field_id": "123"
},
{
"field_name": "test1",
"field_value": "test1",
"field_id": "1231"
},
{
"field_name": "test2",
"field_value": "test2",
"field_id": "1232"
}]
D2 document
"fields":[
{
"field_name": "test1",
"field_value": "testda",
"field_id": "123a"
},
{
"field_name": "test1ad",
"field_value": "test1",
"field_id": "1231"
},
{
"field_name": "test2a",
"field_value": "test2a",
"field_id": "1231"
}]
Fields 是带有文本和关键字映射的嵌套对象
"fields": {
"type": "nested",
"properties": {
"field_id": {
"type": "text",
"fields": {
"raw": {
"type": "keyword"
}
}
},
"field_name": {
"type": "text",
"fields": {
"raw": {
"type": "keyword"
}
}
},
"field_value": {
"type": "text",
"fields": {
"raw": {
"type": "keyword"
}
}
}
}
}
这是我的弹性搜索查询
GET myindex/_search
{
"query": {
"bool": {
"filter": {
"nested":{
"path":"fields",
"query":{
"bool":{
"must":{
"bool":{
"must":[{
"match":{
"field_id.raw": "1231"
}
},
{
"match":{
"field_value.raw": "test1"
}
},
{
"match":{
"field_name.raw": "test1"
}
}]
}
}
}
}
}
}
}
}
}
我没有得到任何回应。 我只想返回第一个文档,因为它在同一个对象中匹配,而不是文档 2,它也在这里和那里有匹配。 在此先感谢...
【问题讨论】:
标签: elasticsearch