2013-03-07 91 views
2

我有以下指標:多個屬性

curl -XPUT "http://localhost:9200/test/" -d ' 
{ 
    "mappings": { 
     "files": { 
      "properties": { 
       "name": { 
        "type": "string", 
        "index": "not_analyzed" 
       }, 
       "owners": { 
        "type": "nested", 
        "properties": { 
         "name": { 
          "type":"string", 
          "index":"not_analyzed" 
         }, 
         "mail": { 
          "type":"string", 
          "index":"not_analyzed" 
         } 
        } 
       } 
      } 
     } 
    } 
} 
' 

隨着樣本文件:

curl -XPUT "http://localhost:9200/test/files/1" -d ' 
{ 
    "name": "first.jpg", 
    "owners": [ 
     { 
      "name": "John Smith", 
      "mail": "[email protected]" 
     }, 
     { 
      "name": "Joe Smith", 
      "mail": "[email protected]" 
     } 
    ] 
} 
' 

curl -XPUT "http://localhost:9200/test/files/2" -d ' 
{ 
    "name": "second.jpg", 
    "owners": [ 
     { 
      "name": "John Smith", 
      "mail": "[email protected]" 
     }, 
     { 
      "name": "Ann Smith", 
      "mail": "[email protected]" 
     } 
    ] 
} 
' 

curl -XPUT "http://localhost:9200/test/files/3" -d ' 
{ 
    "name": "third.jpg", 
    "owners": [ 
     { 
      "name": "Kate Foo", 
      "mail": "[email protected]" 
     } 
    ] 
} 
' 

,我需要找到匹配一些查詢所有業主,讓我們說「MIT」 :

curl -XGET "http://localhost:9200/test/files/_search" -d ' 
{ 
    "facets": { 
     "owners": { 
      "terms": { 
       "field": "owners.name" 
      }, 
      "facet_filter": { 
       "query": { 
        "query_string": { 
         "query": "*mit*", 
         "default_field": "owners.name" 
        } 
       } 
      }, 
      "nested": "owners" 
     } 
    } 
} 
' 

這給了我以下結果:

{ 
    "facets" : { 
    "owners" : { 
     "missing" : 0, 
     "_type" : "terms", 
     "other" : 0, 
     "total" : 4, 
     "terms" : [ 
     { 
      "count" : 2, 
      "term" : "John Smith" 
     }, 
     { 
      "count" : 1, 
      "term" : "Joe Smith" 
     }, 
     { 
      "count" : 1, 
      "term" : "Ann Smith" 
     } 
     ] 
    } 
    }, 
    "timed_out" : false, 
    "hits" : {...} 
} 

沒關係。 但我需要的是讓所有者使用他們的電子郵件地址(對於每個條目我都需要額外的結果字段)。 它可以實現嗎?

回答

4

不可能我想?根據您的需求,我會

  1. 既名稱&電子郵件創建一個複合領域,做對即場分面,或
  2. 除了面運行查詢,並從查詢結果提取出來,但這顯然不可擴展
  3. 兩步操作,獲取方面,建立所需的查詢和合並結果。
+0

感謝您的提示。我已經嘗試過複合材料領域,我認爲這是目前最好的方法,因爲我想避免太多的查詢和處理。乾杯! – 2013-03-12 10:55:04