gpt4 book ai didi

elasticsearch - 需要帮助在Elasticsearch中将通配符搜索与范围查询结合起来吗?

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

我正在尝试在 flex 搜索查询中将通配符与日期范围结合在一起,但没有根据通配符搜索给出响应。它返回的响应包含日期范围不正确的项目。

{
"from": 0,
"size": 10,
"query": {
"bool": {
"must": [
{
"bool": {
"should": [
{
"wildcard": {
"hostName": "*abc*"
}
},
{
"range": {
"requestDate": {
"gte": "2019-10-01T08:00:00.000Z"
}
}
}
]
}
}
]
}
}
}

索引映射如下所示:
{
"index_history": {
"mappings": {
"applications_datalake": {
"properties": {
"query": {
"properties": {
"term": {
"properties": {
"server": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
}
},
"index-data-type": {
"properties": {
"attributes": {
"properties": {
"wwnListForServer": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
},
"hostName": {
"type": "keyword"
},
"requestDate": {
"type": "date"
},
"requestedBy": {
"properties": {
"id": {
"type": "keyword"
},
"name": {
"type": "keyword"
}
}
}
}
}
}
}
}

最佳答案

您错过了minimum_should_match参数,
看一下这个 :
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html
我认为您的查询应如下所示:

{
"from": 0,
"size": 10,
"query": {
"bool": {
"must": [
{
"bool": {
"should": [
{
"wildcard": {
"hostName": "*abc*"
}
},
{
"range": {
"requestDate": {
"gte": "2019-10-01T08:00:00.000Z"
}
}
}
],
"minimum_should_match" : 2
}
}
]
}
}
}

从文档中:

You can use the minimum_should_match parameter to specify the number or percentage of should clauses returned documents must match.

If the bool query includes at least one should clause and no must or filter clauses, the default value is 1. Otherwise, the default value is 0.

关于elasticsearch - 需要帮助在Elasticsearch中将通配符搜索与范围查询结合起来吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59701281/

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