【问题标题】:Elasticsearch index sub-property of non-indexed property非索引属性的 Elasticsearch 索引子属性
【发布时间】:2020-03-03 23:15:47
【问题描述】:

我在elasticsearch中有如下映射:

{
  "doc": {
    "properties": {
      "fileContent": {
        "properties": {
          "dimension": {
            "properties": {
              "jurisdiction": {
                "type": "string"
              },
              "language": {
                "type": "string"
              },
              "region": {
                "type": "string"
              },
              "trueValue": {
                "type": "string"
              }
            }
          },
          "dynamicGeneratedProperty1": {},
          "dynamicGeneratedProperty2": {},
          "dynamicGeneratedPropertyN": {}
        }
      }
    }
  }
}

我正在尝试将 elasticsearch 配置为仅索引 fileContent 中的 dimension 属性,但其他属性是动态生成的,我不想被索引。

我尝试了以下配置,但似乎无法正常工作:

curl -XPUT 0:9200/river1/doc/_mapping -d '
  {
    "doc": {
      "properties": {
        "fileContent": {
          "type": "object",
          "store": true,
          "enabled": false,
          "properties": {
            "dimension": {
              "type": "object",
              "store": true,
              "enabled": true
            }
          }
        }
      }
    }
  }
'

它从父属性应用 "enabled": false 配置,即 fileContent,它忽略子属性配置,它告诉索引 尺寸。

我知道还有一些模板配置,您可以在其中告诉 elastic 根据定义的模板索引属性,您可以在其中指定某种正则表达式:https://www.elastic.co/guide/en/elasticsearch/reference/0.90/indices-templates.html。但是具体怎么用我就不知道了。

我使用的是相当旧的 elasticsearch 版本,0.93。

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    我已经找到了这个问题的答案。解决方案是为 fileContent 对象使用设置为 falsedynamic 属性。这是它的文档:https://www.elastic.co/guide/en/elasticsearch/reference/0.90/mapping-dynamic-mapping.html

    因此,最终配置应如下所示:

    curl -XPUT 0:9200/river1/doc/_mapping -d '
        {
          "doc": {
            "properties": {
              "fileContent": {
                "type": "object",
                "dynamic": false,
                "properties": {
                  "dimension": {
                    "type": "object",
                    "dynamic": true
                  }
                }
              }
            }
          }
        }
    '
    

    这将不允许 elasticsearch 索引并在 fileContent 对象中添加任何其他属性,而 dimensions 属性可以动态填充和索引。

    【讨论】:

      猜你喜欢
      • 2013-06-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-04
      • 1970-01-01
      • 2012-07-16
      • 1970-01-01
      相关资源
      最近更新 更多