0
我有我的Elasticsearch索引下面的映射結構。Elasticsearch:如何檢索只需要的嵌套對象
{
"users": {
"mappings": {
"user-type": {
"properties": {
"lastModifiedBy": {
"type": "string"
},
"lastModifiedDate": {
"type": "date",
"format": "dateOptionalTime"
},
"details": {
"type": "nested",
"properties": {
"lastModifiedBy": {
"type": "string"
},
"lastModifiedDate": {
"type": "date",
"format": "dateOptionalTime"
},
"views": {
"type": "nested",
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
},
"properties": {
"properties": {
"name": {
"type": "string"
},
"type": {
"type": "string"
},
"value": {
"type": "string"
}
}
}
}
}
}
}
}
}
}
}
}
基本上我只想檢索內部基於索引ID &視圖id(details.views.id)的詳細信息視圖對象。
我試着用下面的java code.But似乎不工作。
SearchRequestBuilder srq = this.client.prepareSearch(this.indexName)
.setTypes(this.type)
.setQuery(QueryBuilders.termQuery("_id", sid))
.setPostFilter(FilterBuilders.nestedFilter("details.views",
FilterBuilders.termFilter("details.views.id", id)));
下面是該java代碼的查詢結構。
{
"query": {
"term": {
"_id": "123"
}
},
"post_filter": {
"nested": {
"filter": {
"term": {
"details.views.id": "def"
}
},
"path": "details.views"
}
}
}
您能提供一個您認爲應該由您的查詢返回的示例文檔,但不是嗎? –
在過去的一年中,我寫了大量的Java查詢語句,這裏是我的建議:不要從編寫Java語言的ES查詢開始。我首先使用SoapUI(它是免費的)將查詢發送到ES REST端點。一旦我的查詢工作,然後我將其轉換爲Java。您可以使用Poster通過瀏覽器發送查詢,但您需要保存所有示例查詢;海報只保存一個查詢。 – Paul
@SananAhrens它基本上不返回任何東西。我期待只有個別的視圖對象匹配的ID。 – Suresh