2016-06-17 82 views
0

我正在使用Elasticsearch 1.7並遇到以下問題: 當一個屬性被命名爲索引類型時,我無法過濾屬性而不涉及類型名稱。我更好地展示一個例子:Elasticsearch類型和屬性名稱推理

索引:

curl -XPUT "http://localhost:9200/myindex/ingredient/1" -d' 
{ 
    "name": "salad" 
}' 

curl -XPUT "http://localhost:9200/myindex/product/1" -d' 
{ 
    "name": "sandwich", 
    "ingredient": { 
    "name": "salad" 
    } 
}' 

過濾:

curl -XGET "http://localhost:9200/myindex/_search" -d' 
{ 
    "query": { 
    "term": { 
     "ingredient.name": "salad" 
    } 
    } 
}' 

響應:

{ 
    "_index": "myindex", 
    "_type": "ingredient", 
    "_id": "1", 
    "_score": 1, 
    "_source": { 
    "name": "salad" 
    } 
} 

問題: 的響應類型的成分。我想獲得具有屬性ingredient.name =「沙拉」的對象。 Elasticsearch將屬性名稱理解爲一種類型。當我過濾product.ingredient.name =「沙拉」時,我得到了預期的產品。

我不能得到我想過濾的東西的類型,有沒有另一種說法,我的意思是屬性名稱,而不是一種類型?

回答

1

這是彈性搜索中的一個已知問題:1.x其中有多種方法可以引用導致歧義的一個字段。

周圍有沒有更好的方式,除了

一)明確地在前面加上type作爲OP提到

二)限制搜索到特定type
http://localhost:9200/myindex/<type>/_search

這是固定在elasticsearch 2.x.來自elastica的blog對此有很好的解釋。

+0

謝謝,爲了清除。我想,我必須更新。 –