我有以下資料樣本:
{
"_index" : "index-stats-202110",
"_type" : "_doc",
"_id" : "yT7vlHwBLghXjfKlKm7e",
"_score" : 9.583174,
"_source" : {
"client_id" : "111f34db-c88c-4675-8a69-f3028b3dfa18",
"campaign_id" : "2c3c62f7-9e77-48df-a211-108a2220a063",
"created_at" : "1634586272",
"date_start" : "1634580000",
"date_end" : "1634583600",
"specs" : [
"events",
"general"
],
"data" : {
"count" : 13
}
}
},
{
"_index" : "index-stats-202110",
"_type" : "_doc",
"_id" : "yj7vlHwBLghXjfKlKm7e",
"_score" : 9.583174,
"_source" : {
"client_id" : "111f34db-c88c-4675-8a69-f3028b3dfa18",
"campaign_id" : "2c3c62f7-9e77-48df-a211-108a2220a063",
"created_at" : "1634586272",
"date_start" : "1634580000",
"date_end" : "1634583600",
"specs" : [
"events",
"visit"
],
"data" : {
"label" : "visit",
"count" : 13
}
}
},
{
"_index" : "index-stats-202110",
"_type" : "_doc",
"_id" : "yz7vlHwBLghXjfKlKm7e",
"_score" : 9.583174,
"_source" : {
"client_id" : "111f34db-c88c-4675-8a69-f3028b3dfa18",
"campaign_id" : "2c3c62f7-9e77-48df-a211-108a2220a063",
"created_at" : "1634586272",
"date_start" : "1634580000",
"date_end" : "1634583600",
"specs" : [
"events"
],
"data" : {
"count" : 1
},
"geo" : {
"country" : "q",
"province" : "q",
"city" : "t"
}
}
},
{
"_index" : "index-stats-202110",
"_type" : "_doc",
"_id" : "zD7vlHwBLghXjfKlKm7e",
"_score" : 9.583174,
"_source" : {
"client_id" : "111f34db-c88c-4675-8a69-f3028b3dfa18",
"campaign_id" : "2c3c62f7-9e77-48df-a211-108a2220a063",
"created_at" : "1634586272",
"date_start" : "1634580000",
"date_end" : "1634583600",
"specs" : [
"events"
],
"data" : {
"count" : 1
},
"geo" : {
"country" : "j",
"province" : "q",
"city" : "d"
}
}
}
我從查詢中得到:
{
"query": {
"bool": {
"must": [
{
"term": {
"client_id": "111f34db-c88c-4675-8a69-f3028b3dfa18"
}
},
{
"term": {
"campaign_id": "2c3c62f7-9e77-48df-a211-108a2220a063"
}
},
{
"term": {
"specs": "events"
}
}
]
}
}
}
這是我的映射:
{
"properties":{
"specs":{
"type":"keyword"
},
"campaign_id":{
"type":"keyword"
},
"client_id":{
"type":"keyword"
},
"created_at":{
"type":"date"
},
"date_start":{
"type":"date"
},
"date_end":{
"type":"date"
},
"geo":{
"type":"nested",
"properties":{
"country":{
"type":"keyword"
},
"province":{
"type":"keyword"
},
"city":{
"type":"keyword"
}
}
},
"data":{
"enabled":false
}
}
}
我想獲取geo.country = 'q'我的示例中的內容,但是當我嘗試執行以下查詢時,我得到一個空回應:
{
"query": {
"bool": {
"must": [
{
"term": {
"client_id": "111f34db-c88c-4675-8a69-f3028b3dfa18"
}
},
{
"term": {
"campaign_id": "2c3c62f7-9e77-48df-a211-108a2220a063"
}
},
{
"term": {
"specs": "events"
}
},
{
"term": {
"geo.country": "q"
}
}
]
}
}
}
問題:如何geo.country = 'q'從串列中分離?
uj5u.com熱心網友回復:
您可以使用嵌套查詢和bool/must子句來獲得所需的結果
{
"query": {
"bool": {
"must": [
{
"term": {
"client_id": "111f34db-c88c-4675-8a69-f3028b3dfa18"
}
},
{
"term": {
"campaign_id": "2c3c62f7-9e77-48df-a211-108a2220a063"
}
},
{
"term": {
"specs": "events"
}
},
{
"nested": {
"path": "geo",
"query": {
"term": {
"geo.country": "q"
}
}
}
}
]
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/330910.html
標籤:弹性搜索
