elasticsearch - 在 Elasticsearch 中映射具有任意数量属性的对象

标签 elasticsearch

我有一个给定的文件:

{
  "foo": {}
}

foo 可以有任意数量的属性。假设我将数百万个文档导入到我的索引中,其中每个 foo 的属性都有其他值。

这意味着我将动态构建的映射将变得非常庞大。有什么方法可以告诉 elasticsearch 类似

take everything you have in foo and just accept it as it is (or stringify foo) without having a resulting million-lines-mapping???

还是在索引文档之前我必须自己处理?

如果是这样,我认为有两个解决方案

  1. JSON.stringify foo

  2. foo 中的每个属性映射到键/值对中,并创建一个对象数组:

    // object
    {
      "foo": [
        {"key": "bar1", "value": "bar1's value"},
        {"key": "bar2", "value": "bar2's value"}
      ]
    }
    
    // resulting mapping
    {
      "type": {
        "properties": {
          "foo": {
            "properties": {
              "key": {
                "type": "string" 
              },
              "value": {
                "type": "string" 
              }
            }
          }
        }
      }   
    }
    

您更喜欢解决方案 1 还是 2,为什么?

感谢您的帮助!

最佳答案

您不能让 Elasticsearch 为您将其字符串化。您可以让它忽略“foo”下的任何内容,它将成为“_source”的一部分,但这样它就根本无法搜索了。

第二种方法可能很有意义,具体取决于您将如何查询它,以及您对将接受的值类型了解多少。

Dynamic Type with Mappings 有一个相关问题描述这种方法,这里有一个可运行的例子:https://www.found.no/play/gist/7596633

想法是每个值都有一个嵌套文档。如果每个文档的值数量不是很大,这会很有效。如果您不使用嵌套文档,则搜索“key”:“bar1”和“value”:“bar2 的值”时将返回您的文档。

关于elasticsearch - 在 Elasticsearch 中映射具有任意数量属性的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20265107/

相关文章:

elasticsearch - 将数据从 Dynamodb 发送到 Amazon Elasticsearch 的最佳方式

elasticsearch - elasticsearch-php 2.0 $ client-> mlt($ query)返回 “No handler found for uri”

elasticsearch - 如何在复合聚合中对术语聚合的文档计数进行排序?

json - 在哪里找到ElasticSearch的数据

highcharts - 如何将我们自己的图表添加到 Kibana 中?

elasticsearch - 始终具有和不具有空格的Elasticsearch索引测量单位

elasticsearch - 查询输出到电子邮件操作

c# - 基于第三方ElasticSearch解决方案在解决方案中制作对象模型

node.js - 如何在Node.js中添加多行无痛代码

syntax - 如何在 ElasticSearch 1.0 的聚合范围查询中使用 doc_count