簡體   English   中英

彈性搜索處理丟失的索引

[英]Elastic search handling missing indices

我想知道是否有一種方法可以指定我不介意的彈性搜索或我的搜索查詢中的錯誤索引。 換句話說,我有一個查詢,它試圖查詢7個不同的索引,但其中一個可能會丟失,具體取決於具體情況。 我想知道的是,如果有辦法說,忘記破碎的那個並得到其他6個指數的結果?

    SearchRequestBuilder builder = elasticsearchClient.getClient().prepareSearch(indices)
            .setQuery(Query.buildQueryFrom(term1, term2))
            .addAggregation(AggregationBuilders.terms('term')
                                        .field('field')
                                        .shardSize(shardSize)
                                        .size(size)
                                        .minDocCount(minCount));

作為示例查詢,您可以找到上面的查詢。

看一下ignore_unavailable選項,它是多索引語法的一部分 至少從版本1.3開始就可以使用它,並允許您在執行搜索時忽略丟失或關閉的索引(以及其他多索引操作)。

它由IndicesOptions在Java API中IndicesOptions 瀏覽源代碼,我發現在示例中使用的SearchRequestBuilder上有一個setIndicesOptions()方法。 您需要傳遞一個IndicesOptions實例。

IndicesOptions類上有各種靜態工廠方法,用於使用您特定的所需選項構建實例。 你可能會使用更方便受益lenientExpandOpen()工廠方法(或已經過時的版本, lenient()這取決於您的版本),其中規定ignore_unavailable = TRUE,allow_no_indices = true,並且expand_wildcards =開放

以下是示例查詢的修改版本,它應該提供您要查找的行為:

SearchRequestBuilder builder = elasticsearchClient.getClient().prepareSearch(indices)
        .setQuery(Query.buildQueryFrom(term1, term2))
        .addAggregation(AggregationBuilders.terms('term')
                                    .field('field')
                                    .shardSize(shardSize)
                                    .size(size)
                                    .minDocCount(minCount))
        .setIndicesOptions(IndicesOptions.lenientExpandOpen());

您是否嘗試過使用索引別名

您可以指定單個索引值,而不是引用單個別名。 在這背后可以是幾個索引。

在這里,我將向別名添加兩個索引並刪除丟失/損壞的索引:

curl -XPOST 'http://localhost:9200/_aliases' -d '
{
   "actions" : [
      { "remove" : { "index" : "bad-index", "alias" : "alias-index" } },
      { "add" : { "index" : "good-index1", "alias" : "alias-index" } },
      { "add" : { "index" : "good-index2", "alias" : "alias-index" } }
   ]
}'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM