我有以下弹性搜索索引
{
"companies": {
"aliases": {},
"mappings": {
"properties": {
"industries": {
"type": "nested",
"properties": {
"_id": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"description": {
"type": "text"
},
"priority": {
"type": "integer"
},
"title": {
"type": "text"
}
}
}
}
}
}
}
我想搜索所有公司,其中industries数组包含id=81ca8f45-5b6a-11-d96b4-0242ac110002的标签。
我尝试了以下查询,但无法使其与任何文档匹配。
{
"query": {
"bool": {
"should": [
{
"nested": {
"path": "industries",
"query": {
"bool": {
"should": [
{
"term": {
"industries._id": "81ca8f45-5b6a-11ed-96b4-0242ac110002"
}
}
]
}
}
}
},
{
"term": {
"industries._id": "81ca8f45-5b6a-11ed-96b4-0242ac110002"
}
}
]
}
}
}
是否可以匹配_id字段?因为我测试了下面的术语查询,它给我返回了一个好结果。
{
"query": {
"bool": {
"should": [
{
"term": {
"industries.priority": 1
}
}
]
}
}
}
尝试使用带有关键字字段的术语查询。更改为";工业_id关键字";
{
"query": {
"bool": {
"should": [
{
"nested": {
"path": "industries",
"query": {
"bool": {
"should": [
{
"term": {
"industries._id.keyword": "81ca8f45-5b6a-11ed-96b4-0242ac110002"
}
}
]
}
}
}
},
{
"term": {
"industries._id.keyword": "81ca8f45-5b6a-11ed-96b4-0242ac110002"
}
}
]
}
}
}