
[英]Elasticsearch match_bool_prefix query fails with ampersand at the end of the query
[英]ELK bool query with match and prefix
我是 ELK 的新手。 我对以下搜索查询有疑问:
curl --insecure -H "Authorization: ApiKey $ESAPIKEY" -X GET "https://localhost:9200/commsrch/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": {
"bool": {
"should" : [
{"match" : {"cn" : "franc"}},
{"prefix" : {"srt" : "99889300200"}}
]
}
}
}
'
我需要找到满足条件的所有文档:OR 字段“cn”包含“franc”或字段“srt”以“99889300200”开头。
索引映射:
{
"commsrch" : {
"mappings" : {
"properties" : {
"addr" : {
"type" : "text",
"index" : false
},
"cn" : {
"type" : "text",
"analyzer" : "compname"
},
"srn" : {
"type" : "text",
"analyzer" : "srnsrt"
},
"srt" : {
"type" : "text",
"analyzer" : "srnsrt"
}
}
}
}
}
索引设置:
{
"commsrch" : {
"settings" : {
"index" : {
"routing" : {
"allocation" : {
"include" : {
"_tier_preference" : "data_content"
}
}
},
"number_of_shards" : "1",
"provided_name" : "commsrch",
"creation_date" : "1675079141160",
"analysis" : {
"filter" : {
"ngram_filter" : {
"type" : "ngram",
"min_gram" : "3",
"max_gram" : "4"
}
},
"analyzer" : {
"compname" : {
"filter" : [
"lowercase",
"stop",
"ngram_filter"
],
"type" : "custom",
"tokenizer" : "whitespace"
},
"srnsrt" : {
"type" : "custom",
"tokenizer" : "standard"
}
}
},
"number_of_replicas" : "1",
"uuid" : "C15EXHnaTIq88JSYNt7GvA",
"version" : {
"created" : "8060099"
}
}
}
}
}
查询仅在一个条件下正常工作。 如果查询只有“匹配”条件,则结果具有正确的文档计数。 如果查询只有“前缀”条件,则结果具有正确的文档计数。
如果有两个条件“匹配”和“前缀”,我在结果文档中看到仅对应“前缀”条件。
在 ELK 文档中找不到关于混合“前缀”和“匹配”的任何限制,但我发现存在一些问题。 请大家帮忙看看是哪里出了问题。
您可以使用_count
API 检查匹配和前缀查询的文档计数。
下面是一个如何检查响应文档计数的示例。
GET /my-index-000001/_count
{
"query" : {
"term" : { "user.id" : "kimchy" }
}
}
在继续的经验中,我还有一个问题。 例子:
{
"query": {
"bool": {
"should" : [
{"match" : {"cn" : "one"}},
{"prefix" : {"cn" : "one"}}
]
}
}
}
'
据我了解,高分获得第一份文件,因为它有更多的“一”重复。 但是我需要文档的高分,在字段“cn”中至少有一个单词从字符串“one”开始。 我有查询实验:
{
"query": {
"bool": {
"should": [
{"match": {"cn": "one"}},
{
"constant_score": {
"filter": {
"prefix": {
"cn": "one"
}
},
"boost": 100
}
}
]
}
}
}
但它不能正常工作。 我的查询有什么问题?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.