-3
我有一個彈性搜索索引,其中的列是Country和Expertise。我需要編寫一個查詢在那裏我能得到它的 國家記錄是(美國或英國) 和 專長(植物學或物理)彈性搜索查詢:(A或B)和(C或D)
我怎樣寫這個查詢?
我有一個彈性搜索索引,其中的列是Country和Expertise。我需要編寫一個查詢在那裏我能得到它的 國家記錄是(美國或英國) 和 專長(植物學或物理)彈性搜索查詢:(A或B)和(C或D)
我怎樣寫這個查詢?
您可以使用bool
和terms
查詢做到這一點象下面這樣:
{
"query": {
"bool": {
"must": [
{
"terms": {
"Country": [
"USA",
"UK"
]
}
},
{
"terms": {
"Expertise": [
"Botany",
"Physics"
]
}
}
]
}
}
}
在另一方面,你只能使用bool
查詢做到這一點:
{
"query": {
"bool": {
"must": [
{
"bool": {
"should": [
{
"term": {
"Country": {
"value": "USA"
}
}
},
{
"term": {
"Country": {
"value": "UK"
}
}
}
]
}
},
{
"bool": {
"should": [
{
"term": {
"Expertise": {
"value": "Botany"
}
}
},
{
"term": {
"Expertise": {
"value": "Physics"
}
}
}
]
}
}
]
}
}
}
但是,請看看documentation在問任何其他問題之前。也許,你可能會發現一個較短的查詢。
謝謝。第二個選項奏效。 –