elasticsearch - Elasticsearch动态类型和not_analyse字段

标签 elasticsearch elasticsearch-mapping

我创建了一个像这样的动态模板,因为我有dynamic types:

{
  "template": "test-*", //match any index that starts with 'test-'
  "settings": {
    "number_of_shards": 5
  },
  "mappings": {
    "_default_": {
      "_all": {
        "enabled": false
      },
      "dynamic_templates": [
        {
          "test_id": {
            "match": "test_id", // This is an Array of strings field ["a","b"]
            "mapping": {
              "type": "string",
              "index": "not_analyzed"
            }
          }
        },
        {
          "branch_id": {
            "match": "branch_id", // This is Array of objects field [{"a": "b"}, {"c": "d"}]
            "mapping": {
              "type": "string",
              "index": "not_analyzed"
            }
          }
        }
      ]
    }
  }
}

示例文件:
{
  "_index": "test-data13",
  "_type": "025e179ccfd79cacd92f61bb17bddcf8abf83dc2",
  "_id": "847",
  "_version": 1,
  "_score": 1,
  "_source": {
    "test_id": [
      "test_id_test_10123" // disable indexing or full text search for this Array of string
    ],
    "branch_id": [ // disable indexing or full text search for this Array of hashes
      {
        "1": "test_id_test_10123"
      },
      {
        "2": "test_id_test_10124"
      }
    ]
  }
}

如何以不对带有值的test_id字段和branch_id字段进行索引或分析的方式更改此模板?如果值是一个Array和Object Array,not_analyzed可以工作吗?

最佳答案

index选项设置为no并将enabled设置为false应当确保未索引test_id数组和branch_id对象。

示例:

{
   "template": "test-*",
   "settings": {
      "number_of_shards": 5
   },
   "mappings": {
      "_default_": {
         "_all": {
            "enabled": false
         },
         "dynamic_templates": [
            {
               "test_id": {
                  "match": "test_id",
                  "mapping": {
                     "index": "no"
                  }
               }
            },
            {
               "branch_id": {
                  "match": "branch_id",
                  "mapping": {
                     "index": "no",
                     "enabled": false
                  }
               }
            }
         ]
      }
   }
}

关于elasticsearch - Elasticsearch动态类型和not_analyse字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39379434/

相关文章:

python-2.7 - Elasticsearch : es. index() 消息推送时改变映射

elasticsearch - 我可以使用 elasticsearch 仅存储非结构化数据吗?

elasticsearch - 尝试通过Parital更新文档,但是在获取有关epoch_second格式的日期字段时出现错误

elasticsearch - 如何将 Kafka 批量读取到 Elasticsearch

linux - 使用位于单独文件中的 json 运行 curl -X PUT

javascript - ElasticSearch 错误 : [term] query does not support different field names, 使用 [bool] 查询代替

elasticsearch - Elasticsearch-将文档拆分为单独索引的含义

elasticsearch - elasticsearch 是如何处理不同任务的优先级的?

php - 签署 ElasticSearch AWS 调用

java - Elastic Search 过滤了具有未映射字段的别名