2014-04-28 44 views
2

我有2個單獨的索引,每個索引都包含不同的類型 我想從兩者中獲取組合記錄。elasticsearch index_name with multi_field

的問題是,一種類型具有字段「電子郵件」,其他有「work_email」。不過,我想將它們作爲排序目的相同的東西。 這就是爲什麼我嘗試在其中一種類型中使用index_name

這裏是映射:

指數1:

"mappings": { 
    "people": { 
     "properties": { 
      "work_email": { 
       "type": "string", 
       "index_name": "email", 
       "fields": { 
       "raw": { 
        "type": "string", 
        "index": "not_analyzed" 
       } 
       } 
      } 
     } 
    } 
    } 

索引2:

"mappings": { 
    "companies": { 
     "properties": { 
      "email": { 
       "type": "string", 
       "fields": { 
       "raw": { 
        "type": "string", 
        "index": "not_analyzed" 
       } 
       } 
      } 
     } 
    } 
    } 

我希望這個工作:

GET /index1,index2/people,companies/_search? 
{ 
    "sort": [ 
    { 
     "email.raw": { 
     "order": "asc" 
     } 
    } 
    ] 
} 

但是,我得到一個錯誤,在「人員」類型中沒有這樣的字段。 我做錯了什麼,還是有更好的方法來實現我所需要的?

在這裏你可以找到一個休閒腳本說明了這個問題:https://gist.github.com/pmishev/11375297

+0

你有沒有想過這個?發現這個問題研究同樣的問題。在我的情況下,我也指定了index_name,但結果相同。 – InfinitiesLoop

回答

0

我結束了我的映射添加一個「copy_to」屬性:

"mappings": { 
"people": { 
    "properties": { 
     "work_email": { 
      "type": "string", 
      "copy_to": "email", 
      "fields": { 
      "raw": { 
       "type": "string", 
       "index": "not_analyzed" 
      } 
      } 
     } 
    } 
} 

}

所以,現在我可以解決這兩個領域電子郵件。 這並不理想,因爲這意味着電子郵件字段實際上被索引了兩次,但這是唯一有效的工作。

0

有一個在你映射了多field..Check出下面的映射,並嘗試index..You應該得到的結果的方式問題

"mappings": { 
"people": { 
    "properties": { 
      "work_email":{ 
      "type": "multi_field", 
      "fields": { 
       "work_email":{ 
        "type": "string", 
        "index_name": "email" 
       }, 
       "raw":{ 
        "type": "string", 
        "index": "not_analyzed" 
       } 
      } 
     } 
     } 
     } 
     } 

我們應該指定multi_field和下的字段,我們應該指定所需的字段類型....

+0

謝謝你的回覆,但結果是一樣的。你的映射只是舊格式,它在版本1.0 [link](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/_multi_fields.html)中被刪除了。 – pmishev