【问题标题】:Elasticsearch - How to Generate Facets for Doubly Nested ObjectsElasticsearch - 如何为双重嵌套对象生成 Facet
【发布时间】:2020-03-26 20:02:00
【问题描述】:

使用 elasticsearch 7,我正在尝试为双重嵌套对象构建构面。 因此,在下面的示例中,我想从 ArtistMakerPerson 字段中提取艺术家 ID 代码。我可以拉出嵌套在单个深度的关联,但我无法获得嵌套嵌套对象的语法。

您可以在 Kibana 中使用以下代码重新创建示例。

我的映射如下所示:

PUT test_artist
{
  "settings": {
    "number_of_shards": 1
  },
  "mappings": {
      "properties": {
        "object" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" : "keyword"
            }
          },
          "copy_to" : [
            "global_search"
          ]
        },
        "uniqueID" : {
          "type" : "keyword",
          "copy_to" : [
            "global_search"
          ]
        },
        "artistMakerPerson" : {
          "type" : "nested",
          "properties" : {
            "association" : {
              "type" : "keyword"
            },
            "name" : {
              "type" : "nested",
              "properties" : {
                "id" : {
                  "type" : "keyword"
                },
                "text" : {
                  "type" : "text",
                  "fields" : {
                    "raw" : {
                      "type" : "keyword"
                    }
                  },
                  "copy_to" : [
                    "gs_authority"
                  ]
                }
              }
            },
            "note" : {
              "type" : "text"
            }
          }
        }
      }
    }
}

索引文档:

PUT /test_artist/_doc/123
{
  "object": "cup",
  "uniquedID": "123",
  "artistMakerPerson" : [
              {
                "name" : {
                  "text" : "Johann Kandler",
                  "id" : "A6734"
                },
                "association" : "modeller",
                "note" : "probably"
              },
              {
                "name" : {
                  "text" : "Peter Reinicke",
                  "id" : "A27702"
                },
                "association" : "designer",
                "note" : "probably"
              }
            ]
} 

我正在使用此查询来提取artistMakerPerson.association 的构面或聚合

GET test_artist/_search
{
  "size": 0,
  "aggs": {
    "artists": {
      "nested": {
        "path": "artistMakerPerson"
      },
      "aggs": {
        "kinds": {
          "terms": {
            "field": "artistMakerPerson.association",
            "size": 10
          }
        }
      }
    }
  }
}

我得到了设计师和建模师的奖励,但是当我尝试提取更深的艺术家 ID 时却一无所获:

GET test_artist/_search
{
  "size": 0,
  "aggs": {
    "artists": {
      "nested": {
        "path": "artistMakerPerson"
      },
      "aggs": {
        "kinds": {
          "terms": {
            "field": "artistMakerPerson.name.id",
            "size": 10
          }
        }
      }
    }
  }
}

我做错了什么?

【问题讨论】:

    标签: elasticsearch elasticsearch-aggregation


    【解决方案1】:

    将路径从artistMakerPerson 更改为artistMakerPerson.name

    GET test_artist/_search
    {
      "size": 0,
      "aggs": {
        "artists": {
          "nested": {
            "path": "artistMakerPerson.name"
          },
          "aggs": {
            "kinds": {
              "terms": {
                "field": "artistMakerPerson.name.id",
                "size": 10
              }
            }
          }
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多