gpt4 book ai didi

elasticsearch - 术语查询在 Elasticsearch 中不起作用?

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

嗨,我正在尝试发出curl命令,以从我的 flex 搜索索引(mep-reports)中检索某些文档,它是如何工作的。
想象如果我执行以下curl命令,它将返回数据

curl -XGET 'localhost:52671/mep-reports*/_search?size=1' -H 'Content-Type: application/json' -d @query1.txt
响应
{
"took": 6,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 100,
"max_score": null,
"hits": [
{
"_index": "mep-reports",
"_type": "doc",
"_id": "99",
"_score": null,
"_source": {
"inventory": "SMS",
"msg_text": "This is random text",
"status": "ENROUTE",
"@timestamp": "2019-09-10T07:06:26.287Z",
"o_error": "",
"flight_id": "92348fa1-ca6c-456a-b3b2-85fba2d2deed",
"recipient": "420736408281",
"account_id": "a56f7e14-20f9-40e6-90c6-10604140ac5f",
"sender": "8800111",
"campaign_id": "6f2abca3-b46d-43f3-91be-3278a8dd7dc0",
"nof_segments": 1,
"@version": 1,
"submission_ts": 1568105380000000,
"delivery_ts": 1553616888000000,
"campaign_name": "Starbucks Promotion",
"flight_name": "Extremely very very long flight",
"campaign_type": "NON_MARKETING"
},
"sort": [
1568099186287
]
}
]
}
}
query1.txt文件的内容。
{
"from": 0,
"size": 10,
"timeout": "300s",
"query": {
"bool": {
"must": [
{
"range": {
"@timestamp": {
"from": "2019-08-31T23:00:00.000Z",
"to": null,
"include_lower": true,
"include_upper": true,
"format": "yyyy-MM-dd'T'HH:mm:ss.SSSZ",
"boost": 1.0
}
}
},
{
"range": {
"@timestamp": {
"from": null,
"to": "2019-09-12T07:06:26.287Z",
"include_lower": true,
"include_upper": true,
"format": "yyyy-MM-dd'T'HH:mm:ss.SSSZ",
"boost": 1.0
}
}
},
{
"match": {
"account_id": {
"query": "a56f7e14-20f9-40e6-90c6-10604140ac5f",
"operator": "OR",
"prefix_length": 0,
"max_expansions": 50,
"fuzzy_transpositions": true,
"lenient": false,
"zero_terms_query": "NONE",
"auto_generate_synonyms_phrase_query": true,
"boost": 1.0
}
}
}
],
"adjust_pure_negative": true,
"boost": 1.0
}
},
"sort": [
{
"@timestamp": {
"order": "desc"
}
}
]
}
但是,当我修改query1.txt以搜索文档以包含对campaign_type的字词查询时,它不起作用。
   curl -XGET 'localhost:52671/mep-reports*/_search?size=1' -H 'Content-Type: application/json' -d @query.txt
响应
{"took":6,"timed_out":false,"_shards":{"total":5,"successful":5,"skipped":0,"failed":0},"hits":{"total":0,"max_score":null,"hits":[]}}
修改后的查询。 query.txt文件内容
{
"from": 0,
"size": 10,
"timeout": "300s",
"query": {
"bool": {
"must": [
{
"range": {
"@timestamp": {
"from": "2019-08-31T23:00:00.000Z",
"to": null,
"include_lower": true,
"include_upper": true,
"format": "yyyy-MM-dd'T'HH:mm:ss.SSSZ",
"boost": 1.0
}
}
},
{
"range": {
"@timestamp": {
"from": null,
"to": "2019-09-12T07:06:26.287Z",
"include_lower": true,
"include_upper": true,
"format": "yyyy-MM-dd'T'HH:mm:ss.SSSZ",
"boost": 1.0
}
}
},
{
"match": {
"account_id": {
"query": "a56f7e14-20f9-40e6-90c6-10604140ac5f",
"operator": "OR",
"prefix_length": 0,
"max_expansions": 50,
"fuzzy_transpositions": true,
"lenient": false,
"zero_terms_query": "NONE",
"auto_generate_synonyms_phrase_query": true,
"boost": 1.0
}
}
},
{
"terms": {
"campaign_type": [
"NON_MARKETING"
],
"boost": 1.0
}
}
],
"adjust_pure_negative": true,
"boost": 1.0
}
},
"sort": [
{
"@timestamp": {
"order": "desc"
}
}
]
}
我希望上面的查询返回一些结果。唯一的区别是我在广告系列类型字段中添加了字词查询。
这是我的 flex 搜索映射文档
{
"mappings": {
"doc": {
"properties": {
"@timestamp": {
"type": "date"
},
"@version": {
"type": "text"
},
"account_id": {
"type": "keyword"
},
"campaign_id": {
"type": "keyword"
},
"delivery_ts": {
"type": "date",
"format": "epoch_millis"
},
"submission_ts": {
"type": "date",
"format": "epoch_millis"
},
"flight_id": {
"type": "keyword"
},
"inventory": {
"type": "keyword"
},
"msg_text": {
"type": "keyword"
},
"nof_segments": {
"type": "keyword"
},
"o_error": {
"type": "keyword"
},
"recipient": {
"type": "text"
},
"sender": {
"type": "keyword"
},
"status": {
"type": "keyword"
},
"campaign_name": {
"type": "keyword"
},
"flight_name": {
"type": "keyword"
},
"campaign_type": {
"type": "keyword"
}
}
}
}
}
如果您能帮助的话,我非常感谢。
我也观察到以下查询工作正常
{"from":0,"size":10,"timeout":"300s","query":{"bool":{"must":[{"range":{"@timestamp":{"from":"2019-08-31T23:00:00.000Z","to":null,"include_lower":true,"include_upper":true,"format":"yyyy-MM-dd'T'HH:mm:ss.SSSZ","boost":1.0}}},{"range":{"@timestamp":{"from":null,"to":"2019-09-12T07:06:26.287Z","include_lower":true,"include_upper":true,"format":"yyyy-MM-dd'T'HH:mm:ss.SSSZ","boost":1.0}}},{"match":{"recipient":{"query":"420736408281","operator":"OR","prefix_length":0,"max_expansions":50,"fuzzy_transpositions":true,"lenient":false,"zero_terms_query":"NONE","auto_generate_synonyms_phrase_query":true,"boost":1.0}}},{"match":{"account_id":{"query":"a56f7e14-20f9-40e6-90c6-10604140ac5f","operator":"OR","prefix_length":0,"max_expansions":50,"fuzzy_transpositions":true,"lenient":false,"zero_terms_query":"NONE","auto_generate_synonyms_phrase_query":true,"boost":1.0}}},{"match":{"campaign_id":{"query":"6f2abca3-b46d-43f3-91be-3278a8dd7dc0","operator":"OR","prefix_length":0,"max_expansions":50,"fuzzy_transpositions":true,"lenient":false,"zero_terms_query":"NONE","auto_generate_synonyms_phrase_query":true,"boost":1.0}}},{"match":{"flight_id":{"query":"92348fa1-ca6c-456a-b3b2-85fba2d2deed","operator":"OR","prefix_length":0,"max_expansions":50,"fuzzy_transpositions":true,"lenient":false,"zero_terms_query":"NONE","auto_generate_synonyms_phrase_query":true,"boost":1.0}}},{"terms":{"status":["enroute"],"boost":1.0}},{"terms":{"inventory":["sms"],"boost":1.0}}],"adjust_pure_negative":true,"boost":1.0}},"sort":[{"@timestamp":{"order":"desc"}}]}

最佳答案

术语查询不会被分析并用于精确或关键字搜索,在您的第一个查询中,您使用的是匹配查询,该查询已被分析,并且使用了与索引时间相同的分析器,因此得到了结果。
如果要获取术语查询的结果,请使用campaign_type.keyword(如果它在映射中存在)(如果是动态生成的),否则,您需要创建一个关键字字段来存储它并在该字段上查询。
请引用elastic post explaining diff b/w term and match query

关于elasticsearch - 术语查询在 Elasticsearch 中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63686839/

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