弹性搜索中的嵌套文档

Nested documents in Elastic Search

我们有一个程序将使用 ElasticSearch。我们有使用join查询的需求,elasticsearch是不支持的,所以要么是嵌套关系,要么是父子关系。我读到使用父子关系会导致 significant performance issues,所以我们正在考虑使用嵌套文档。

我们 index/query 在产品上,但我们也有客户和供应商。所以,这是我对产品映射的想法:

{
    "mappings" : {
      "products" : {
        "dynamic": false,
        "properties" : {
          "availability" : {
            "type" : "text"
          },
          "customer": {
              "type": "nested"
          },
          "vendor": {
              "type": "nested"
          },
          "color" : {
                "type" : "text"
            }
          },
          "created_date" : {
            "type" : "text"
          }
        }
      }
    }
}

这里的 customer 和 vendor 是我映射的字段。

这个映射看起来正确吗?由于我将dynamic设置为false,是否需要指定customer和vendor子文档的内容?如果是这样,我该怎么做?

我的团队发现 parent/child 关系对我们的表现极为不利,所以我认为您可能会做出使用嵌套字段的正确决定。

如果您使用 dynamic: false 则未定义的字段将不会添加到映射中。您可以将其设置为 true 并在索引时添加这些字段,或者您可以自己定义嵌套文档的属性:

{
"mappings" : {
  "products" : {
    "dynamic": false,
    "properties" : {
      ...
      "customer": {
          "type": "nested",
          "properties": {
              "prop a": {...},
              "prop b": {...}
          }
      },
      "vendor": {
          "type": "nested",
          "properties": {
              "prop a": {...},
              "prop b": {...}
          }
      },
      ...
    }
  }
}
}