elasticsearch - 如何使用 elasticsearch_dsl 创建动态映射
问题描述
我必须创建应该看起来像这样的映射。
{
"mappings": {
"properties": {
"product_id": {
"type": "keyword"
},
"attributes": {
"dynamic": "true",
"properties": {}
},
}
}
我通常会做这样的事情
class RetailerProductGeneric(Document):
product_id = Keyword()
当我在文档中有动态模式时,我该怎么做?
我查看了文档,但对我来说不是很清楚。它是这样的:
class Post(Document):
title = Text()
class Meta:
all = MetaField(enabled=False)
dynamic = MetaField('strict')
不知道这里发生了什么。有人可以解释一下怎么做吗?
编辑1:
经过一番研究,我想出了如何创建动态映射。
class RetailerProductGeneric(Document):
product_id = Keyword()
attributes = Object(dynamic=True)
但现在预期的映射结果是这样的
"attributes": {
"dynamic": true,
"type": "object"
},
我正在寻找的是
"attributes": {
"dynamic": "true",
"properties": {}
},
它有什么区别?如何按预期进行映射。
解决方案
Good start!!
"attributes": {
"dynamic": true,
"type": "object"
},
and
"attributes": {
"dynamic": "true",
"properties": {}
},
are actually exactly the same thing.
When type: object
is specified, properties: {}
is implied
And when properties: {}
is specified and no type
is given, then type: object
is implied.
推荐阅读
- azure - Azure Devops 可以免费更改用户吗?
- android - Playstore 锁屏打开时 inappreview 触发器
- bash - 为什么 C 文件名可以在编写 bash 脚本后立即保存在变量中?
- c++ - OBS 如何将某物区分为 3rd 方覆盖?
- reactjs - 来自后端(API)的列不适用于 useState
- python - 在属性/方法 Django 中访问自引用对象
- linux - 如果第一个 bash 命令的输出输出零行,如何执行第二个 bash 命令?
- mysql - HAVING COUNT 语句
- android - JDK 1.8.x 的要求检查失败!检测到的版本:13.0.1
- c - 在 gdb 中,我们可以将变量设置为表达式吗?