【问题标题】:not_analyzed for a nested type on ElasticSearch?not_analyzed 用于 ElasticSearch 上的嵌套类型?
【发布时间】:2013-06-27 18:13:09
【问题描述】:

我在对嵌套对象执行分面搜索时遇到问题。

以我有以下文件为例:

tags: [
   {
       tag: "tag0",
       tag_url: "http://xxxxxxx.com/tag/tag0/"
   },
   {
       tag: "tag1",
       tag_url: "http://xxxxxx.com/tag/tag1/"
   }
],

categories: [
    {
        category: "cat0",
        category_url: "http://xxxxxx.com/category/cat0/"
    },
    {
        category: "cat1",
        category_url: "http://xxxxxx.com/category/cat1/"
    }
],

我想在tags.tagtags.tag_url 上执行一个方面

那么我使用什么映射来为嵌套字段创建index:not_analyzed

我试过这个映射:

    mapping_data[mapping_name]["properties"] = {
        "tags.tag" : {
            "type": "multi_field",
                "fields" : {
                    "tags.tag": {"type" : "string", "index" : "analyzed", "store": "yes"},
                    "untouched" : {"type" : "string", "index" : "not_analyzed"}
                }
        },
        "tags.tag_url" : {
            "type": "multi_field",
                "fields" : {
                    "tags.tag_url": {"type" : "string", "index" : "analyzed", "store": "yes"},
                    "untouched" : {"type" : "string", "index" : "not_analyzed"}
                }
        },
        "categories.category" : {
            "type": "multi_field",
                "fields" : {
                    "categories.category": {"type" : "string", "index" : "analyzed", "store": "yes"},
                    "untouched" : {"type" : "string", "index" : "not_analyzed"}
                }
        }, 
        "categories.category_url" : {
            "type": "multi_field",
                "fields" : {
                    "categories.category_url": {"type" : "string", "index" : "analyzed", "store": "yes"},
                    "untouched" : {"type" : "string", "index" : "not_analyzed"}
                }
        },

}

mapping_data[mapping_name]["properties"] = {
        "tags" : {
            "type": "nested"
        },

        "categories" : {
            "type": "nested"
        }, 
}

但它没有给我所需的结果。

使用type:nested,仍然标记嵌套字段,而type: multi_field不能表示嵌套字段为not_analyzed。 (请注意,我在multi_field 变体中使用了tags.tag,但无济于事。)

那么,如何表达映射以实现嵌套文档的方面?

PS:http://www.elasticsearch.org/guide/reference/mapping/nested-type/http://www.elasticsearch.org/guide/reference/mapping/nested-type/ 没有产生我需要的结果,因为我没有 value_field。

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    以下是您应该为 tags 嵌套字段使用的 json 映射:

    {
        "type" : {
            "properties" : {
                "tags" : {
                    "type": "nested",
                    "properties" : {
                        "tag" : {
                            "type": "multi_field",
                            "fields" : {
                                "tag": {"type" : "string", "index" : "analyzed", "store": "yes"},
                                "untouched" : {"type" : "string", "index" : "not_analyzed"}
                            }
                        },
                        "tag_url" : {
                            "type": "multi_field",
                            "fields" : {
                                "tag_url": {"type" : "string", "index" : "analyzed", "store": "yes"},
                                "untouched" : {"type" : "string", "index" : "not_analyzed"}
                            }
                        }
                    }
                }
            }
        }
    }
    

    定义一个包含属性的嵌套对象非常好,属性可以是任何类型,在您的情况下为multi_field

    然后您可以像这样在tags.untouched 字段上创建所需的构面:

    {
        "query" : {
          "match_all" : {} 
        },
        "facets": {
          "tags": {
            "terms": {
              "field": "tags.tag.untouched",
              "size": 10
            },
            "nested" : "tags"
          }
        }
    }
    

    我使用最新版本的 elasticsearch 对此进行了测试。请记住,嵌套构面的制作方式自 0.90 以来已发生变化。查看this issue 了解更多信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-24
      相关资源
      最近更新 更多