我有一个简单的文档结构,如下所示。
{
"did" : "1",
"uid" : "user1",
"mid" : "pc-linux1",
"path" : "/tmp/path1"
}
我需要查询elastic,它完全匹配所有字段
GET index2/_search
{
"query": {
"bool":{
"must": [
{
"term" : { "uid" : "user1"}
},
{
"term" : { "mid" : "pc-linux1"}
},
{
"term" : { "did" : "1"}
},
{
"term" : { "path" : "/tmp/path1"}
}
]
}
}
}
匹配应该在没有任何形式的关键字“ flex ”分析的情况下进行,以便将“/ tmp / path1”作为一个完整术语进行匹配。
我试图使用自定义映射:
"index" : false
这不起作用。
PUT /index2?include_type_name=true
{
"mappings" : {
"_doc": {
"properties" : {
"did" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"index" : false,
"ignore_above" : 256
}
}
},
"mid" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"index" : false,
"ignore_above" : 256
}
}
},
"path" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"index" : false,
"ignore_above" : 256
}
}
},
"uid" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"index" : false,
"ignore_above" : 256
}
}
}
}
}
}
}
我正在使用elastic7.0,很少有文章建议使用
"index" : "not_analysed"
在Elastic 7.0中未被接受为有效映射
有什么建议么?
最佳答案
如果要匹配精确术语,请尝试以下查询:
GET index2/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"uid": "user1"
}
},
{
"match": {
"mid": "pc-linux1"
}
},
{
"match": {
"did": "1"
}
},
{
"match": {
"path": "/tmp/path1"
}
}
]
}
}
}
关于elasticsearch - 查询以查找与查询中所有字段完全匹配的所有文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59945705/