使用NEST ElasticClient仅检索内部_id
我尝试使用NEST ElasticClient执行搜索,只获取点击的_id 这是我的密码:使用NEST ElasticClient仅检索内部_id,
Warning: implode(): Invalid arguments passed in /data/phpspider/zhask/webroot/tpl/detail.html on line 45
,,我尝试使用NEST ElasticClient执行搜索,只获取点击的_id 这是我的密码: var client = new ElasticClient(); var searchResponse = client.Search<ElasticResult>(new SearchRequest { From = this.query.Page * 100, Size = 100, Source = new SourceFilter
var client = new ElasticClient();
var searchResponse = client.Search<ElasticResult>(new SearchRequest {
From = this.query.Page * 100,
Size = 100,
Source = new SourceFilter {
Includes = "_id"
},
Query = new QueryStringQuery {
Query = this.query.Querystring
}
});
public class ElasticResult {
public string _id;
}
var client=new ElasticClient();
var searchResponse=client.Search(新的SearchRequest{
From=this.query.Page*100,
尺寸=100,
Source=新的SourceFilter{
Includes=“\u id”
},
Query=新建QueryStringQuery{
Query=this.Query.Querystring
}
});
公共类弹性结果{
公共字符串_id;
}
但是文档(ElasticResult对象)的_id始终为空。我做错了什么?该
\u id
不是\u源文件的一部分,而是命中数组中每个命中的命中元数据的一部分
仅返回\u id
字段的最简洁的方法是在嵌套中以FilterPath
的形式公开
private static void Main()
{
var defaultIndex = "documents";
var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
var settings = new ConnectionSettings(pool)
.DefaultIndex(defaultIndex)
.DefaultTypeName("_doc");
var client = new ElasticClient(settings);
if (client.IndexExists(defaultIndex).Exists)
client.DeleteIndex(defaultIndex);
client.Bulk(b => b
.IndexMany<object>(new[] {
new { Message = "hello" },
new { Message = "world" }
})
.Refresh(Refresh.WaitFor)
);
var searchResponse = client.Search<object>(new SearchRequest<object>
{
From = 0 * 100,
Size = 100,
FilterPath = new [] { "hits.hits._id" },
Query = new QueryStringQuery
{
Query = ""
}
});
foreach(var id in searchResponse.Hits.Select(h => h.Id))
{
// do something with the ids
Console.WriteLine(id);
}
}
\u id
不是\u源文件的一部分,而是hits数组中每个命中的命中元数据的一部分
仅返回\u id
字段的最简洁的方法是在嵌套中以FilterPath
的形式公开
private static void Main()
{
var defaultIndex = "documents";
var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
var settings = new ConnectionSettings(pool)
.DefaultIndex(defaultIndex)
.DefaultTypeName("_doc");
var client = new ElasticClient(settings);
if (client.IndexExists(defaultIndex).Exists)
client.DeleteIndex(defaultIndex);
client.Bulk(b => b
.IndexMany<object>(new[] {
new { Message = "hello" },
new { Message = "world" }
})
.Refresh(Refresh.WaitFor)
);
var searchResponse = client.Search<object>(new SearchRequest<object>
{
From = 0 * 100,
Size = 100,
FilterPath = new [] { "hits.hits._id" },
Query = new QueryStringQuery
{
Query = ""
}
});
foreach(var id in searchResponse.Hits.Select(h => h.Id))
{
// do something with the ids
Console.WriteLine(id);
}
}
你的意思是你得到了结果(文档)但_id为空吗?@LijuL:是的,就是这样。你的意思是你得到了结果(文档)但_id为空吗?@LijuL:是的,就是这样。这实际上是在搜索还是只是从ES返回文档id?@sramalingam24它执行实际的搜索(虽然在本例中,空的query\u字符串
query将计算为嵌套的无条件查询,因此与no query子句相同)。@RussCam一旦使用FilterPath,响应将不再包含空的scrollId。是否可以在FilterPath中指定scrollId?我尝试了“scrollId”和“scroll\u id”但两者都不起作用。这是实际执行搜索还是仅从ES返回文档ID?@sramalingam24它执行实际搜索(尽管在本例中,空的query\u字符串
query将计算为嵌套无条件查询,因此与无查询子句相同).@RussCam一旦使用FilterPath,响应将不再包含为null的scrollId。是否可以在FilterPath中指定scrollId?我尝试了“scrollId”和“scroll_id”,但两者都不起作用。