給定檔案:書籍
[
{
name: "book a",
authors:
[
{
name: "John",
}
{
name: "Paul"
}
]
},
{
name: "book b",
authors:
[
{
name: "Paul"
}
]
}
]
目標:回傳匹配name=book a并且將作者姓名之一與authors.name=匹配的書John。
我嘗試了什么:
"must": [
{
"bool": {
"should": [
{
"bool": {
"must": [
{
"term": {
"name": {
"value": "book a"
}
}
},
{
"bool": {
"should": [
{
"term": {
"authors.name": {
"value": "John"
}
}
}
]
}
}
]
}
}
]
}
}
]
映射名稱:文本作者:動態
uj5u.com熱心網友回復:
您可以使用以下查詢:
請注意,如果您使用的是彈性搜索的動態映射,則使用name.keywordand authors.name.keyword。否則使用name并且authors.name如果您指定了自定義映射。
{
"query": {
"bool": {
"must": [
{
"match": {
"name": "book a"
}
},
{
"term": {
"authors.name.keyword": {
"value": "John"
}
}
}
]
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/518153.html
標籤:弹性搜索布尔查询
