我有以下彈性搜索索引
{
"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"
}
}
}
}
}
}
}
我想搜索所有行業陣列包含帶有_id = 81ca8f45-5b6a-11ed-96b4-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
}
}
]
}
}
}
uj5u.com熱心網友回復:
嘗試使用帶有關鍵字欄位的術語查詢。更改為“industries._id.keyword”
{
"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"
}
}
]
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/530379.html
標籤:php弹性搜索翁格
