elasticsearch - 查询以查找与查询中所有字段完全匹配的所有文档

标签 elasticsearch

我有一个简单的文档结构,如下所示。

{
    "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/

相关文章:

mysql - 尽管我在RDS实例的安全组中指定了入站规则,但登录失败

Ubuntu - Elasticsearch - 错误 : Cannot allocate memory

php - PHP-Elasticsearch:更新多个文档

javascript - 将日志从Javascript发送到ElasticSearch

elasticsearch - 容器化WebApp的日志不会通过Serilog.Sinks.Elasticsearch发送到Elasticsearch

json - `min_score`不能在Elasticsearch中重新评分't work for `

elasticsearch - 在一次调用中从 Elasticsearch 中获取完整的树

python - Elasticsearch 1.7 scripted_metric 分析字符串

elasticsearch - Elasticsearch.Net和NEST同时搜索标签的字符串和数组

elasticsearch - 如何嵌套结构化过滤查询?