gpt4 book ai didi

elasticsearch - 如何通过ID和过滤字段值进行过滤?

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

如何添加其他过滤器以匹配category所有字段中的blog.post.notes值?首先,我想按ID进行过滤,然后按注释类别进行过滤,可以吗?

我只能按ID进行过滤:

GET posts/posts/_search?fields=_id&_source=blog.post.notes
{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"ids": {
"values": [
"100000000001234"
]
}
}
}
}
}

如何过滤例如当前结果中的“测试”类别:
{
"took": 58,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1,
"hits": [{
"_index": "posts",
"_type": "posts",
"_id": "100000000001234",
"_score": 1,
"_source": {
"blog": {
"post": {
"notes": {
"main": [{
"message": "blablabla",
"category": "test"
}, {
"message": "blablabla",
"category": "other"
}],
"cart": [{
"message": "blablabla",
"category": "test"
}, {
"message": "blablabla",
"category": "other"
}]
}
}
}
}
}]
}
}

curl -XGET本地主机:9200 / posts / _mapping / posts
{
"posts": {
"mappings": {
"posts": {
"dynamic_templates": [{
"blog": {
"mapping": {
"index": "analyzed"
},
"path_match": "blog.*",
"path_unmatch": "*.medias.*"
}
}, {
"ids": {
"mapping": {
"index": "not_analyzed",
"type": "string"
},
"match": "_id|base_id",
"match_pattern": "regex"
}
}],
"_all": {
"enabled": false
},
"properties": {
"query": {
"properties": {
"filtered": {
"properties": {
"filter": {
"properties": {
"ids": {
"properties": {
"values": {
"type": "string"
}
}
}
}
},
"query": {
"properties": {
"match_all": {
"type": "object"
}
}
}
}
},
"match_all": {
"type": "object"
}
}
},
"source": {
"dynamic": "true",
"properties": {
"post": {
"dynamic": "true",
"properties": {
"_id": {
"type": "string",
"index": "not_analyzed"
},
"base_id": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
},
"blog": {
"properties": {
"post": {
"properties": {
"_id": {
"type": "string"
},
"notes": {
"properties": {
"main": {
"properties": {
"id": {
"type": "string"
},
"message": {
"type": "string"
},
"category": {
"type": "string"
}
}
},
"cart": {
"properties": {
"id": {
"type": "string"
},
"message": {
"type": "string"
},
"category": {
"type": "string"
}
}
}
}
}
}
}
}
}
}
}
}
}
}

最佳答案

您可以在ID和字词上使用必须使用 bool(boolean) 查询

POST c1_2/Test/_search
{
"query": {
"bool": {
"must": [
{
"ids": {
"values": [
1,
2,
3
]
}
},
{
"terms": {
"blog.post.notes.main.category": [
"categoryfilter"
]
}
}
]
}
}
}

但是,由于您具有主类别和购物车类别,因此必须在每个类别上使用过滤器,在我的示例中,我对主类别进行了过滤,如果您需要对两者进行过滤,则需要再使用一个或将对主类别或购物车类别进行过滤的过滤器

另外,您应该知道不应该对类别进行分析,以便对“我的 super 类别”之类的内容进行过滤,否则其他明智的查询将无法正常工作。


POST c1_2/Blog/1
{
"post": {
"notes": {
"main": [
{
"message": "blablabla",
"category": "test"
},
{
"message": "blablabla",
"category": "other"
}
],
"cart": [
{
"message": "blablabla",
"category": "test"
},
{
"message": "blablabla",
"category": "other"
}
]
}
}
}

POST c1_2/Blog/2
{
"post": {
"notes": {
"main": [
{
"message": "blablabla",
"category": "second"
},
{
"message": "blablabla",
"category": "third"
}
],
"cart": [
{
"message": "blablabla",
"category": "test"
},
{
"message": "blablabla",
"category": "other"
}
]
}
}
}


POST c1_2/Blog/_search
{
"query": {
"bool": {
"must": [
{
"ids": {
"values": [
1,
2,
3
]
}
},
{
"terms": {
"post.notes.main.category": [
"test"
]
}
}
]
}
}
}

关于elasticsearch - 如何通过ID和过滤字段值进行过滤?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35741540/

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