gpt4 book ai didi

java - QueryString 用冒号搜索字符串

转载 作者:行者123 更新时间:2023-12-02 08:47:07 29 4
gpt4 key购买 nike

我正在努力实现以下条件

orgId =“z2store”,类型 =“web”,日期时间 =“12:17:08”

下面是我写的查询

GET /sample/_search
{
"bool" : {
"must" : [
{
"term" : {
"orgId" : {
"value" : "z2store",
"boost" : 1.0
}
}
},
{
"term" : {
"type" : {
"value" : "web",
"boost" : 1.0
}
}
},
{
"query_string" : {
"query" : "12:17:08",
"default_field" : "dateTime",
"fields" : [ ],
"type" : "best_fields",
"default_operator" : "or",
"max_determinized_states" : 10000,
"enable_position_increments" : true,
"fuzziness" : "AUTO",
"fuzzy_prefix_length" : 0,
"fuzzy_max_expansions" : 50,
"phrase_slop" : 0,
"escape" : false,
"auto_generate_synonyms_phrase_query" : true,
"fuzzy_transpositions" : true,
"boost" : 1.0
}
}
],
"adjust_pure_negative" : true,
"boost" : 1.0
}
}

下面是我的java代码

BoolQueryBuilder boolQuery = new BoolQueryBuilder().must(QueryBuilders.termQuery("orgId", orgId))
.must(QueryBuilders.termQuery("type", "web"));
QueryStringQueryBuilder builder = new QueryStringQueryBuilder("12:17:08");
builder.defaultField("dateTime").queryString();
boolQuery.must(builder);
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().query(builder)
.from((batchNumber - 1) * batchSize).size(batchSize)
.sort("@timestamp", SortOrder.DESC);

以上查询不起作用。任何帮助将不胜感激。我使用的是elasticSearch 7.4。

最佳答案

您可以创建 dateTime 字段,类型为 date,格式为 hour_month_second(格式为 HH:mm:ss) 。您可以在此处了解有关不同日期格式的更多信息 https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-date-format.html .

下面是dateTime字段的映射:

{
"mappings": {
"properties": {
"dateTime": {
"type" : "date",
"format" : "hour_minute_second"
}
}
}
}

现在,当您使用以下搜索查询搜索数据时:

{
"query" : {
"bool" : {
"must" : [
{
"term" : {
"orgId" : {
"value" : "z2store",
"boost" : 1.0
}
}
},
{
"term" : {
"type" : {
"value" : "web",
"boost" : 1.0
}
}
},
{
"term" :{
"dateTime":"12:17:08"
}
}
],
"adjust_pure_negative" : true,
"boost" : 1.0
}
}

}

您将得到所需的结果:

"hits": [
{
"_index": "datetimeindexf",
"_type": "_doc",
"_id": "1",
"_score": 1.5753641,
"_source": {
"dateTime": "12:17:08",
"orgId": "z2store",
"type": "web"
}
}
]

关于java - QueryString 用冒号搜索字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61008453/

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