not_analyzed为ElasticSearch上的嵌套类型?

Dja*_*cks 2 elasticsearch

我有一个关于在嵌套对象上执行构面搜索的问题.

举个例子,我有以下文件:

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/"
    }
],
Run Code Online (Sandbox Code Playgroud)

而且我想在tags.tag和上执行一个方面tags.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"}
                }
        },

}
Run Code Online (Sandbox Code Playgroud)

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

        "categories" : {
            "type": "nested"
        }, 
}
Run Code Online (Sandbox Code Playgroud)

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

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

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

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

jav*_*nna 5

以下是您应该用于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"}
                        }
                    }
                }
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

在您的情况下,定义包含属性的嵌套对象是完全没问题的,属性可以是任何类型multi_field.

然后,您可以在tags.untouched字段上创建所需的构面,如下所示:

{
    "query" : {
      "match_all" : {} 
    },
    "facets": {
      "tags": {
        "terms": {
          "field": "tags.tag.untouched",
          "size": 10
        },
        "nested" : "tags"
      }
    }
}
Run Code Online (Sandbox Code Playgroud)

我用最新版本的elasticsearch测试了这个.请记住,嵌套构面的方式自0.90以来已发生变化.看看这个问题就知道了.