2013-06-30 72 views
2

我有一个关于在嵌套对象上执行facet搜索的问题。not_analyzed在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/" 
    } 
], 

,我想对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。

回答

5

以下是JSON映射,你应该使用的tags嵌套领域:

{ 
    "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了解更多。

相关问题