2013-06-30 120 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瞭解更多。

相關問題