我陷于一个问题,显然我可能误解了一些东西,但这就是问题所在。
我在数据库中有一些测试数据,但是当我运行它时:
与弹性连接
private string uri = "http://localhost:9200/";
private string testindex = "testconnectiones";
private static ElasticClient GetClient(string testindex, string uri)
{
var pool = new SingleNodeConnectionPool(new Uri(uri));
var connectionSettings =
new ConnectionSettings(pool, sourceSerializer: JsonNetSerializer.Default).DefaultIndex(testindex);
return new ElasticClient(connectionSettings);
}
然后
public void TestCreateIndexBaseOnOrderId1()
{
var client = GetClient(testindex, uri);
var searchResponse = client.Search<TestLogs>(s => s
.AllTypes()
.From(0)
.Size(1000)
.Analyzer("standard")
.Query(q => q
.Match(m => m
.Field(f => f.OrderID)
.Query("")
)
)
);
var eventTestArray = searchResponse.Documents.Select(x => new {x.OrderID }).ToArray();
Console.WriteLine("searchResponse.Documents.Count: " + searchResponse.Documents.Count());
var i = 0;
var j = 0;
foreach (var s in eventTestArray)
{
Console.WriteLine($"{i}: " + s);
i++;
}
Assert.AreNotEqual(eventTestArray, null);
}
输出仅为:
searchResponse.Documents.Count: 0.
搜索响应中应该有10个订单。
我只是想知道我是否误解了什么。
数据库中的数据看起来像这样
{
"_index": "testconnectiones",
"_type": "logs",
"_id": "1",
"_version": 1,
"found": true,
"_source": {
"OrderId": 1,
"Event": "CreateOrder"
}
}
答案 0 :(得分:0)
使用类型TestLogs
时,客户如何知道以testconnectiones
索引为目标?
有几件事要考虑:
testconnectiones
索引f => f.OrderID
会序列化为字符串值,以定位Elasticsearch中用于类型和索引的字段。默认情况下,NEST骆驼在序列化时会使用属性名称.Verbatim()
可以完全按原样对查询进行序列化答案 1 :(得分:0)
现在解决了一部分问题。
QueryContainer query = new TermQuery()
{
Field = "OrderId",
Value = "1"
};
var searchRequest = new SearchRequest(index: "testindex")
{
Query = query
};
var searchResult = client.Search<TestLogs>(searchRequest);
foreach (var s in orderIdArray)
{
Console.WriteLine($"{i}: OrderId:" + s.OrderID + " Event: " + s.Event + " Time: " + s.TimeStamp);
i++;
}
现在只有当我更改
时才是问题 QueryContainer query = new TermQuery()
{
Field = "OrderId",
Value = "1"
};
到...
QueryContainer query = new TermQuery()
{
Field = "OrderId",
Value = "1"
};
不会给出任何输出是Test方法ELK_algorithmsTests.TestIndexCreation.testToMakeSameSelectionButWithSelectedEvent引发异常: System.IndexOutOfRangeException:..
任何建议应该放在哪里?因为我现在没有想法。