在Nest ElasticSearch

时间:2018-06-18 14:47:49

标签: c# elasticsearch nest

是否有办法通过Nest在ElasticSearch中重用Client.Search和Client.Count的流畅查询?

以下是定义搜索流畅定义的代码段的开头。

 System.Func<SearchDescriptor<Documents.City>, ISearchRequest> x = s => 
 s.Index(IndexNames.Cities).From(0)
   .Size(100)
   .Query(q => q.Bool(.....

计数的变化将是SearchDescriptor - &gt; CountDescriptor和ISearchRequest - &gt; ICountRequest。看起来需要编写两次查询,因为如果没有正在播放的类型的前期知识,流畅的标记将无法编译。

基本问题是,使用Nest查询执行搜索和计数请求是否有任何简洁的可维护方法?

1 个答案:

答案 0 :(得分:2)

不要重复使用搜索部分,而是尝试使用查询:

master <- read.table("~/Desktop/Heatmap Project/master.txt", sep = "\t", header = T, stringsAsFactors = F)

vector_a <- master$Median_A
vector_b <- master$Median_B

heatmap_prep <- function(vector_a,vector_b){
    dummy <- as.data.frame(matrix(0, ncol=length(vector_b), nrow=length(vector_a))
    for (i in 1:length(vector_a)){
        first_number <- vector_a[i]
        for(j in 1:length(vector_b)){
            second_number <- vector_b[j]
            result <- cor(vector_a,vector_b)
            dummy [i,j] <- result

        }
    }
    return(dummy)
}

heatmap_data_matrix <- as.matrix(heatmap_prep(vector_a,vector_b))

#Create heatmap:
library(stats)
library(gplots)
library(RColorBrewer)
heatmap(heatmap_data_matrix,Colv = NA, Rowv=NA, revC=T, scale='none', xlab= "B", ylab= "A", main = "Heatmap", col = rev(brewer.pal(11,"RdBu")))

希望有所帮助。