2012-10-29 26 views
11

有人能告訴我,如果在ElasticSearch上有相當於Solr copyField指令嗎?ElasticSarch上Solr的copyField的等價物?

我知道有多字段類型: http://www.elasticsearch.org/guide/reference/mapping/multi-field-type.html 當你想在同一個字段上應用多個分析器時,這很好。

但它不完全一樣。 Solr的許可證「合併」多個字段爲一個:

<field name="id" type="string" indexed="true" stored="true"/> 
<field name="name" type="string" indexed="true" stored="true"/> 
<field name="subject" type="string" indexed="true" stored="true"/> 
<field name="location" type="string" indexed="true" stored="true"/> 
<field name="all" type="text" indexed="true" stored="true" multiValued="true"/> 
<copyField source="*" dest="all"/> 

這個插件是非常有前途的: https://github.com/yakaz/elasticsearch-analysis-combo

,因爲它允許使用ElasticSearch時取回結果爲單場多值字段。 但它仍然不完全相同,因爲它不允許「合併」多個字段。我想組合分析儀和Solr copyField的組合。

我有一個博客文章模型(標題/說明字段),並希望在一個字段「blogContent」上覆制標題和說明,我將在其上應用2個不同的分析器。

ElasticSearch中是否有解決方案?

回答

8

special _all field默認獲得所有其他字段的副本。您可以使用include_in_all屬性來控制包含到_all字段中。但是,你僅限於這樣的一個領域。如果您需要更多,那麼您需要通過搜索多個字段來在搜索端處理它。

它也可以通過使用multi_field"path": "just_name"屬性來實現類似於copyField功能:

curl -XPUT localhost:9200/test-idx -d '{ 
    "settings": { 
     "index": { 
      "number_of_shards": 1, 
      "number_of_replicas": 0 
     } 
    }, 
    "mappings": { 
     "doc": { 
      "properties": { 
       "first_name": { 
        "type": "multi_field", 
        "path": "just_name", 
        "fields": { 
         "first_name": {"type": "string", "index": "analyzed"}, 
         "name": {"type": "string","index": "analyzed"} 
        } 
       }, 
       "last_name": { 
        "type": "multi_field", 
        "path": "just_name", 
        "fields": { 
         "last_name": {"type": "string", "index": "analyzed"}, 
         "name": {"type": "string","index": "analyzed"} 
        } 
       } 
      } 
     } 
    } 
}' 
echo 
curl -XPUT localhost:9200/test-idx/doc/1 -d '{ 
    "first_name": "Sebastien", 
    "last_name": "Lorber" 
}' 
echo 
curl -XPOST localhost:9200/test-idx/_refresh 
echo 
curl "localhost:9200/test-idx/doc/_search?q=name:Sebastien" 
echo 
curl "localhost:9200/test-idx/doc/_search?q=name:Lorber" 
+0

我知道_all但是如果需要能夠創建許多不同的_all –

+1

我同意這將是一個很好的功能。不幸的是,它還沒有實現https://github.com/elasticsearch/elasticsearch/issues/1169 – imotov