gpt4 book ai didi

elasticsearch - Elasticsearch在数组字段中获取全部符合要求的项目?

转载 作者:行者123 更新时间:2023-12-03 01:51:34 24 4
gpt4 key购买 nike

我真的是Elastic Search的新手,现在被一个问题所困扰。

如果我使用GET http://127.0.0.1:9200/index/type/_search,结果是

{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 3,
"max_score": 1,
"hits": [
{
"_index": "index",
"_type": "type",
"_id": "AVe3AcpYbUIbMIPUYcZ2",
"_score": 1,
"_source": {
"applications": [
{
"jobs": [
{
"id": 1,
"country": "a"
},
{
"id": 2,
"country": "b"
}
]
},
{
"jobs": [
{
"id": 3,
"country": "c"
},
{
"id": 4,
"country": "d"
}
]
}
]
}
},
{
"_index": "index",
"_type": "type",
"_id": "AVe3cMaPbUIbMIPUYcaS",
"_score": 1,
"_source": {
"applications": [
{
"jobs": [
{
"id": 11,
"country": "aa"
},
{
"id": 2,
"country": "aa"
}
]
},
{
"jobs": [
{
"id": 33,
"country": "aa"
},
{
"id": 44,
"country": "aa"
}
]
}
]
}
},
{
"_index": "index",
"_type": "type",
"_id": "AVe3b1KmbUIbMIPUYcaR",
"_score": 1,
"_source": {
"applications": [
{
"jobs": [
{
"id": 11,
"country": "aa"
},
{
"id": 2,
"country": "bb"
}
]
},
{
"jobs": [
{
"id": 33,
"country": "cc"
},
{
"id": 44,
"country": "d"
}
]
}
]
}
}
]
}
}

我想要的是获得一个应用程序,该应用程序中的每个job.country为“aa”,因此预期结果为
"applications": [
{
"jobs": [
{
"id": 11,
"country": "aa"
},
{
"id": 2,
"country": "aa"
}
]
},
{
"jobs": [
{
"id": 33,
"country": "aa"
},
{
"id": 44,
"country": "aa"
}
]
}
]

我尝试过的是POST http://127.0.0.1:9200/index/type/_search
{
"query": {
"match": {
"applications.jobs.country": "aa"
}
}
}

但是结果是
{
"took": 65,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 0.30685282,
"hits": [
{
"_index": "index",
"_type": "type",
"_id": "AVe3cMaPbUIbMIPUYcaS",
"_score": 0.30685282,
"_source": {
"applications": [
{
"jobs": [
{
"id": 11,
"country": "aa"
},
{
"id": 2,
"country": "aa"
}
]
},
{
"jobs": [
{
"id": 33,
"country": "aa"
},
{
"id": 44,
"country": "aa"
}
]
}
]
}
},
{
"_index": "index",
"_type": "type",
"_id": "AVe3b1KmbUIbMIPUYcaR",
"_score": 0.15342641,
"_source": {
"applications": [
{
"jobs": [
{
"id": 11,
"country": "aa"
},
{
"id": 2,
"country": "bb"
}
]
},
{
"jobs": [
{
"id": 33,
"country": "cc"
},
{
"id": 44,
"country": "d"
}
]
}
]
}
}
]
}
}

看来,如果应用程序包含符合要求的application.jobs.country,它将被返回。我想得到那些application.jobs满足需要的每一项。有人可以帮助我吗?谢谢

最佳答案

我使用正则表达式来临时解决此问题。
POST http://127.0.0.1:9200/index/type/_search

{
"query": {
"bool": {
"must_not": {
"regexp": {
"applications.jobs.country": "~(.*aa.*)"
}
}
}
}
}

不得包含application.jobs.country包含“aa”以外的内容

关于elasticsearch - Elasticsearch在数组字段中获取全部符合要求的项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40011354/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com