elasticsearch Elasticsearch通配符查询
你能帮我理解,为什么简单的查询不起作用。 我有一个带有默认设置的简单索引:
elasticsearch Elasticsearch通配符查询,
elasticsearch,kibana,
elasticsearch,Kibana,你能帮我理解,为什么简单的查询不起作用。 我有一个带有默认设置的简单索引: PUT my_index/doc/1 { "path": "C:\\Windows\\system32\\cmd.exe" } 为什么下面的查询不返回任何内容 GET my_index/_search { "_source": "path", "query": { "query_string": { "query": "(path: *\\system32\\*.exe)" }
PUT my_index/doc/1
{
"path": "C:\\Windows\\system32\\cmd.exe"
}
为什么下面的查询不返回任何内容
GET my_index/_search
{
"_source": "path",
"query": {
"query_string": {
"query": "(path: *\\system32\\*.exe)"
}
}
}
您应该像这样指定查询中的字段
GET sample-index/_search
{
"query": {
"query_string" : {
"fields" : ["path.keyword"],
"query" : """*\\system32\\*.exe"""
}
}
}
我得到的结果是:
{ "took": 13,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0 },
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "sample-index",
"_type": "doc",
"_id": "1",
"_score": 1,
"_source": {
"path": """C:\Windows\system32\cmd.exe"""
}
}
]
}
}
这里我使用了path.keyword,因为当你发布一个没有映射的新字段(就像你在问题中所做的那样)时,默认情况下它会为它创建一个关键字字段。
额外提示:如果要检查多个字段(例如:path、path1、pathcc等),也可以在field部分应用regex
您应该像这样指定查询中的字段
GET sample-index/_search
{
"query": {
"query_string" : {
"fields" : ["path.keyword"],
"query" : """*\\system32\\*.exe"""
}
}
}
我得到的结果是:
{ "took": 13,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0 },
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "sample-index",
"_type": "doc",
"_id": "1",
"_score": 1,
"_source": {
"path": """C:\Windows\system32\cmd.exe"""
}
}
]
}
}
这里我使用了path.keyword,因为当你发布一个没有映射的新字段(就像你在问题中所做的那样)时,默认情况下它会为它创建一个关键字字段。
额外提示:如果要检查多个字段(例如:path、path1、pathcc等),也可以在field部分应用regex
例如,谢谢你。三重引号的原因是什么?如果我删除它们,结果将为空?您是否尝试在问题中使用post命令查找您发布的条目
GET sample index/\u search/
当我使用搜索查询查看条目时,我得到了这个输出{“\u index”:“sample index”、“\u type”:“doc”、“\u id”:“1”、“\u score”:1、“\u source”:{“path”:“C:\Windows\system32\cmd.exe”“}
谢谢您的示例。三重引号的原因是什么?如果我删除它们,结果将为空?您是否尝试在问题中使用post命令查找您发布的条目GET sample index/\u search/
当我使用搜索查询查看条目时,我得到了这个输出{“\u index”:“sample index”、“\u type”:“doc”、“\u id”:“1”、“\u score”:1、“\u source”:{“path”:“C:\Windows\system32\cmd.exe”}