gpt4 book ai didi

elasticsearch - 如何在搜索查询中编写条件?

转载 作者:行者123 更新时间:2023-12-02 22:21:12 26 4
gpt4 key购买 nike

我在特定地区的文件中搜索。文档具有各种状态。目的是返回所有文档,除非文档的状态码是 ABCD - 仅当 ID 大于 100 时才应返回此类文档。我尝试编写多个查询,包括下面的查询,它仅返回 ABCD ID 大于 100 的文档,并且没有其他文档。这里有什么问题?我怎样才能获得非 ABCD 文件?

    "_source": true,
"from": 0,
"size": 50,
"sort": [
{
"firstStamp": "DESC"
}
],
"query": {
"bool": {
"must": [
{
"term": {
"districtId": "3755"
}
},
{
"bool": {
"must": [
{
"terms": {
"documentStatus.code.keyword": [
"ABCD"
]
}
},
{
"bool": {
"must": {
"script": {
"script": "doc['id'].value > 100"
}
}
}
}
]
}
}
]
}
}
}```

最佳答案

Since you have not added any index mapping, looking at your searchquery data seems to be of object field data type. As far as I canunderstand, your aim is to return all documents, except when thedocument's status code is ABCD and document with status code ABCDshould only be returned if their ID is greater than 100.


添加包含索引数据、搜索查询和搜索结果的工作示例
索引数据:
{
"id":200,
"documentStatus":{
"code":"DEF"
}
}
{
"id":200,
"documentStatus":{
"code":"ABCD"
}
}
{
"id":100,
"documentStatus":{
"code":"ABCD"
}
}
查询查询:
{
"query": {
"bool": {
"should": [
{
"bool": {
"must": [
{
"terms": {
"documentStatus.code.keyword": [
"ABCD"
]
}
},
{
"bool": {
"must": {
"script": {
"script": "doc['id'].value > 100"
}
}
}
}
]
}
},
{
"bool": {
"must_not": {
"terms": {
"documentStatus.code.keyword": [
"ABCD"
]
}
}
}
}
]
}
}
}
搜索结果:
"hits": [
{
"_index": "stof_64351595",
"_type": "_doc",
"_id": "2",
"_score": 2.0,
"_source": {
"id": 200,
"documentStatus": {
"code": "ABCD"
}
}
},
{
"_index": "stof_64351595",
"_type": "_doc",
"_id": "3",
"_score": 0.0,
"_source": {
"id": 200,
"documentStatus": {
"code": "DEF"
}
}
}
]

关于elasticsearch - 如何在搜索查询中编写条件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64351595/

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