我們有一個具有 2 個不同索引的彈性搜索。在一個索引中有一個名為的欄位physical_location,其中包含一個 lat en lon 子欄位。在另一個索引中,有一個program_run.geolocation使用相同的嵌套 lat 和 lon呼叫的欄位。
現在我們要在客戶端 Web 應用程式的地圖上繪制來自兩個索引的檔案。我們嘗試使用布爾查詢
{
"query": {
"bool": {
"should": [
{
"geo_distance": {
"distance": "10km",
"physical_location": {
"lat": 53.193078596551715,
"lon": 6.783202751724139
}
}
},
{
"geo_distance": {
"distance": "10km",
"program_run.geolocation": {
"lat": 53.193078596551715,
"lon": 6.783202751724139
}
}
}
]
}
}
}
但這確實會出錯,因為彈性無法找到第二個索引中的第一個欄位和第一個索引中的第二個欄位。
解決此問題的最佳方法是什么?
- 是否有一種服務器端方式可以將不同索引的查詢與不同的布局組合起來而不會出錯?
- 還是在客戶端結合起來更方便?(以及在這種情況下如何處理總計數)
- 還是重新索引并使兩個索引中的名稱相同的唯一方法?(需要大量的重構作業)。
uj5u.com熱心網友回復:
elasticsearch 論壇上的某個人給出了正確的答案。
您可以為索引映射中的欄位名稱創建別名。因此您可以定義一個“location_for_search”欄位,該欄位通過別名映射到正確的欄位。
作業示例在這里:https : //discuss.elastic.co/t/how-to-combine-results-from-2-elasticsearch-indexes-with-different-layouts/293659/2
uj5u.com熱心網友回復:
編輯:此答案對上述問題無效,請找到支持的答案
我認為第一個選項可以實作,在 Java RestHighLevelClient 中,它有一個可用的建構式,可以采用多個索引名稱和一個搜索查詢。
Constructs a new search request against the provided indices with the given search source
public SearchRequest(String[] indices, SearchSourceBuilder source) {
this();
if (source == null) {
throw new IllegalArgumentException("source must not be null");
}
indices(indices);
this.source = source;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/408451.html
標籤:
