本文整理汇总了C#中ElasticsearchContext.GetDocument方法的典型用法代码示例。如果您正苦于以下问题:C# ElasticsearchContext.GetDocument方法的具体用法?C# ElasticsearchContext.GetDocument怎么用?C# ElasticsearchContext.GetDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ElasticsearchContext
的用法示例。
在下文中一共展示了ElasticsearchContext.GetDocument方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
IElasticsearchMappingResolver elasticsearchMappingResolver = new ElasticsearchMappingResolver();
// You only require a mapping if the default settings are not good enough
//elasticsearchMappingResolver.AddElasticSearchMappingForEntityType(typeof(Skill), new SkillElasticsearchMapping());
using (var elasticSearchContext = new ElasticsearchContext("http://localhost:9200/", elasticsearchMappingResolver))
{
elasticSearchContext.TraceProvider = new TraceProvider("tracingExample");
elasticSearchContext.AddUpdateDocument(TestData.SkillEf, TestData.SkillEf.Id);
elasticSearchContext.AddUpdateDocument(TestData.SkillOrm, TestData.SkillOrm.Id);
elasticSearchContext.AddUpdateDocument(TestData.SkillSQLServer, TestData.SkillSQLServer.Id);
elasticSearchContext.AddUpdateDocument(TestData.SkillGermanWithFunnyLetters, TestData.SkillGermanWithFunnyLetters.Id);
elasticSearchContext.AddUpdateDocument(TestData.SkillLevel, TestData.SkillLevel.Id);
var addEntitiesResult = elasticSearchContext.SaveChanges();
Console.WriteLine(addEntitiesResult.PayloadResult);
Console.WriteLine(addEntitiesResult.Status);
Console.WriteLine(addEntitiesResult.Description);
}
using (var elasticSearchContext = new ElasticsearchContext("http://localhost:9200/", elasticsearchMappingResolver))
{
elasticSearchContext.TraceProvider = new TraceProvider("tracingExample");
// get a entity and update it, then delete an entity
Skill singleEntityWithId = elasticSearchContext.GetDocument<Skill>("11");
singleEntityWithId.Updated = DateTime.UtcNow;
elasticSearchContext.AddUpdateDocument(TestData.SkillOrm, TestData.SkillOrm.Id);
elasticSearchContext.DeleteDocument<Skill>(TestData.SkillEf.Id);
elasticSearchContext.SaveChanges();
elasticSearchContext.AddUpdateDocument(TestData.SkillEf, TestData.SkillEf.Id);
var nextResult = elasticSearchContext.SaveChanges();
Console.WriteLine(nextResult.PayloadResult);
Console.WriteLine(nextResult.Status);
Console.WriteLine(nextResult.Description);
}
using (var elasticSearchContext = new ElasticsearchContext("http://localhost:9200/", elasticsearchMappingResolver))
{
elasticSearchContext.TraceProvider = new TraceProvider("tracingExample");
// deleting indexes are usually not required...
elasticSearchContext.AllowDeleteForIndex = true;
var result = elasticSearchContext.DeleteIndexAsync<SkillLevel>();
result.Wait();
var result1 = elasticSearchContext.DeleteIndexAsync<Skill>();
result1.Wait();
//var result = elasticSearchContext.DeleteIndex<Skill>();
elasticSearchContext.SaveChanges();
//Console.WriteLine(result.Result.PayloadResult);
//Console.WriteLine(result.Result.Status);
//Console.WriteLine(result.Result.Description);
//Console.ReadLine();
}
}
示例2: GetAddressFromElasticsearch
public Address GetAddressFromElasticsearch(int id)
{
Address address;
IElasticsearchMappingResolver ElasticsearchMappingResolver = new ElasticsearchMappingResolver();
using (var ElasticsearchContext = new ElasticsearchContext("http://localhost:9200/", ElasticsearchMappingResolver))
{
address = ElasticsearchContext.GetDocument<Address>(id);
}
return address;
}
示例3: GetPersonFromElasticsearch
public Person GetPersonFromElasticsearch(int id)
{
Person person;
IElasticsearchMappingResolver ElasticsearchMappingResolver = new ElasticsearchMappingResolver();
using (var ElasticsearchContext = new ElasticsearchContext("http://localhost:9200/", ElasticsearchMappingResolver))
{
person = ElasticsearchContext.GetDocument<Person>(id);
}
return person;
}
示例4: DeleteNonExistingChildTypeFromExistingIndex
public void DeleteNonExistingChildTypeFromExistingIndex()
{
CreateIndex();
using (var context = new ElasticsearchContext(ConnectionString, _elasticsearchMappingResolver))
{
var doc1 = context.GetDocument<MappingChildParentRoutingTestsLevel1>(1);
Assert.IsNotNull(doc1);
var doc2 = context.GetDocument<MappingChildParentRoutingTestsLevel2>(2, new RoutingDefinition { ParentId = 1, RoutingId = 1 });
Assert.IsNotNull(doc2);
var doc3 = context.GetDocument<MappingChildParentRoutingTestsLevel3>(3, new RoutingDefinition { ParentId = 2, RoutingId = 1 });
Assert.IsNotNull(doc3);
context.AllowDeleteForIndex = true;
var result = context.DeleteIndexType<MappingChildParentRoutingTestsLevel3>();
Assert.IsTrue(result);
Thread.Sleep(1000);
result = context.DeleteIndexType<MappingChildParentRoutingTestsLevel3>();
Assert.IsFalse(result);
}
}
示例5: TestGetChildItemTestParentDoesNotExist
public void TestGetChildItemTestParentDoesNotExist()
{
const int parentId = 22;
// This could return NOT FOUND 404 or OK 200. It all depends is the routing matches the same shard. It does not search for the exact parent
using (var context = new ElasticsearchContext(ConnectionString, new ElasticsearchSerializerConfiguration(_elasticsearchMappingResolver, SaveChildObjectsAsWellAsParent, ProcessChildDocumentsAsSeparateChildIndex)))
{
context.TraceProvider = new ConsoleTraceProvider();
var roundTripResult = context.GetDocument<ChildDocumentLevelTwo>(71, new RoutingDefinition { ParentId = parentId });
var childDocs = context.Search<ChildDocumentLevelTwo>(BuildSearchForChildDocumentsWithIdAndParentType(parentId, "childdocumentlevelone"));
Assert.IsNotNull(childDocs.PayloadResult.Hits.HitsResult.First(t => t.Id.ToString() == "71"));
Assert.AreEqual(71, roundTripResult.Id);
}
}
示例6: TestCreateIndexNewChildItemTestParentDoesNotExist
public void TestCreateIndexNewChildItemTestParentDoesNotExist()
{
const int parentId = 332;
// This creates a new child doc with the parent 332 even though no parent for 332 exists
using (var context = new ElasticsearchContext(ConnectionString, new ElasticsearchSerializerConfiguration(_elasticsearchMappingResolver, SaveChildObjectsAsWellAsParent, ProcessChildDocumentsAsSeparateChildIndex)))
{
var testObject = new ChildDocumentLevelTwo
{
Id = 47,
D3 = "DoesNotExist.p332.p47"
};
context.TraceProvider = new ConsoleTraceProvider();
context.AddUpdateDocument(testObject, testObject.Id, new RoutingDefinition { ParentId = parentId });
// Save to Elasticsearch
var ret = context.SaveChanges();
Assert.AreEqual(ret.Status, HttpStatusCode.OK);
Thread.Sleep(1500);
var roundTripResult = context.GetDocument<ChildDocumentLevelTwo>(testObject.Id, new RoutingDefinition { ParentId = parentId });
var childDocs = context.Search<ChildDocumentLevelTwo>(BuildSearchForChildDocumentsWithIdAndParentType(parentId, "childdocumentlevelone"));
Assert.IsNotNull(childDocs.PayloadResult.Hits.HitsResult.First(t => t.Id.ToString() == "47"));
Assert.AreEqual(testObject.Id, roundTripResult.Id);
}
}
示例7: CreateNewIndexAndMappingWithSimpleList
public void CreateNewIndexAndMappingWithSimpleList()
{
var mappingTestsParent = new MappingTestsParentWithSimpleList
{
Calls = 3,
MappingTestsParentId = 2,
Call2s="test",
MappingTestsItemIntList = new List<int> { 2, 7, 44, 176},
MappingTestsItemShortArray = new short[] { 4,7,89,9}
};
using (
var context = new ElasticsearchContext(ConnectionString,
new ElasticsearchSerializerConfiguration(_elasticsearchMappingResolver)))
{
context.TraceProvider = new ConsoleTraceProvider();
context.AddUpdateDocument(mappingTestsParent, mappingTestsParent.MappingTestsParentId);
context.SaveChangesAndInitMappings();
Thread.Sleep(1500);
var doc = context.GetDocument<MappingTestsParentWithSimpleList>(mappingTestsParent.MappingTestsParentId);
Assert.IsNotNull(doc);
}
}
示例8: TestDefaultContextDeleteByQuerySingleDocumentWithId
public void TestDefaultContextDeleteByQuerySingleDocumentWithId()
{
const int documentId = 153;
string deleteJson = "{\"query\": { \"term\": { \"_id\": \"" + documentId + "\" }}}";
using (var context = new ElasticsearchContext(ConnectionString, _elasticsearchMappingResolver))
{
context.TraceProvider = new ConsoleTraceProvider();
for (int i = 150; i < 160; i++)
{
context.AddUpdateDocument(_entitiesForTests[i-150], i);
}
// Save to Elasticsearch
var ret = context.SaveChanges();
// Wait for Elasticsearch to update
long foundBefore = 0;
Task.Run(() =>
{
while (true)
{
Thread.Sleep(300);
foundBefore = context.Count<SkillTestEntity>();
if (foundBefore > 9)
{
_resetEvent.Set();
}
}
});
// allow elasticsearch time to update...
WaitForDataOrFail();
Assert.AreEqual(ret.Status, HttpStatusCode.OK);
context.DeleteByQuery<SkillTestEntity>(deleteJson);
// Clear thecache so count or get returns the latest value
context.IndexClearCache<SkillTestEntity>();
long foundAfter = context.Count<SkillTestEntity>();
Console.WriteLine("found before {0}, after {1}", foundBefore, foundAfter);
Assert.Greater(foundBefore, foundAfter);
context.GetDocument<SkillTestEntity>(documentId);
}
}
示例9: TestDefaultContextParentNestedIntArray
public void TestDefaultContextParentNestedIntArray()
{
using (var context = new ElasticsearchContext(ConnectionString, _elasticsearchMappingResolver))
{
context.TraceProvider = new ConsoleTraceProvider();
var skillWithIntArray = new SkillWithIntArray
{
MyIntArray = new[] { 2, 4, 6, 99, 7 },
BlahBlah = "test3 with int array",
Id = 2
};
context.AddUpdateDocument(skillWithIntArray, skillWithIntArray.Id);
// Save to Elasticsearch
var ret = context.SaveChanges();
Assert.AreEqual(ret.Status, HttpStatusCode.OK);
var returned = context.GetDocument<SkillWithIntArray>(2);
Assert.AreEqual(skillWithIntArray.MyIntArray[2], returned.MyIntArray[2]);
}
}
示例10: CreateNewIndexAndMappingWithSimpleNullListAndNullArrayList
public void CreateNewIndexAndMappingWithSimpleNullListAndNullArrayList()
{
var mappingTestsParent = new MappingTestsParentWithSimpleNullAndNullArrayList
{
Calls = 3,
MappingTestsParentId = 2,
Call2s="test"
};
using (
var context = new ElasticsearchContext(ConnectionString,
new ElasticsearchSerializerConfiguration(_elasticsearchMappingResolver)))
{
context.TraceProvider = new ConsoleTraceProvider();
context.AddUpdateDocument(mappingTestsParent, mappingTestsParent.MappingTestsParentId);
context.SaveChangesAndInitMappings();
Thread.Sleep(1500);
var doc = context.GetDocument<MappingTestsParentWithSimpleNullAndNullArrayList>(mappingTestsParent.MappingTestsParentId);
Assert.IsNotNull(doc);
context.IndexClose("mappingtestsparentwithsimplenullandnullarraylists");
context.IndexOpen("mappingtestsparentwithsimplenullandnullarraylists");
var result = context.IndexOptimize("mappingtestsparentwithsimplenullandnullarraylists", new OptimizeParameters{NumberOfShards=3, Flush=true});
Assert.GreaterOrEqual(result.PayloadResult.Shards.Successful, 1);
}
}
示例11: TestDefaultContextParentNestedSkillWithStringAndLongCollection
public void TestDefaultContextParentNestedSkillWithStringAndLongCollection()
{
using (var context = new ElasticsearchContext(ConnectionString, _elasticsearchMappingResolver))
{
context.TraceProvider = new ConsoleTraceProvider();
var skillWithIntArray = new SkillWithStringLongAndDoubleCollection
{
MyStringArray = new List<String>
{
"one", "two","three"
},
BlahBlah = "test3 with int array",
Id = 2,
MyDoubleArray = new List<double> { 2.4, 5.7, 67.345 },
MyLongArray = new List<long> { 34444445, 65432, 7889999 }
};
context.AddUpdateDocument(skillWithIntArray, skillWithIntArray.Id);
// Save to Elasticsearch
var ret = context.SaveChanges();
Assert.AreEqual(ret.Status, HttpStatusCode.OK);
var returned = context.GetDocument<SkillWithStringLongAndDoubleCollection>(2);
Assert.AreEqual(skillWithIntArray.MyStringArray[2], returned.MyStringArray[2]);
Assert.AreEqual(skillWithIntArray.MyDoubleArray[1], returned.MyDoubleArray[1]);
Assert.AreEqual(skillWithIntArray.MyLongArray[1], returned.MyLongArray[1]);
}
}
示例12: TestDefaultContextGetEntityNotFound
public void TestDefaultContextGetEntityNotFound()
{
const int entityId = 39994;
using (var context = new ElasticsearchContext(ConnectionString, _elasticsearchMappingResolver))
{
context.TraceProvider = new ConsoleTraceProvider();
// Get the entity
var entityResult = context.GetDocument<SkillTestEntity>(entityId);
Assert.AreEqual(entityResult.Id, entityId);
}
}
示例13: TestDefaultContextTestJsonIgnore
public void TestDefaultContextTestJsonIgnore()
{
using (var context = new ElasticsearchContext(ConnectionString, _elasticsearchMappingResolver))
{
context.TraceProvider = new ConsoleTraceProvider();
var testJsonIgnore = new TestJsonIgnore
{
MyStringArray = new List<string> {"ff", "dd"},
BlahBlah = "sss",
Id = 3,
MyLongArray = new List<long> {23, 4323456, 333332},
SkillSingleChildElement = new SkillSingleChildElement {Details = "ss", Id = 3},
SkillSingleChildElementList =
new List<SkillSingleChildElement> {new SkillSingleChildElement {Details = "ww", Id = 2}}
};
context.AddUpdateDocument(testJsonIgnore, testJsonIgnore.Id);
// Save to Elasticsearch
context.SaveChanges();
var ret = context.GetDocument<TestJsonIgnore>(3);
Assert.AreEqual(ret.MyLongArray, null);
Assert.AreEqual(ret.SkillSingleChildElement, null);
Assert.AreEqual(ret.SkillSingleChildElementList, null);
Assert.AreEqual(ret.BlahBlahNull, null);
Assert.AreEqual(ret.BlahBlah, "sss");
Assert.AreEqual(ret.Id, 3);
}
}
示例14: TestDefaultContextGetEntityBadUrl
public void TestDefaultContextGetEntityBadUrl()
{
const int entityId = 34;
using (var context = new ElasticsearchContext("http://localghghghhost:9200/", _elasticsearchMappingResolver))
{
context.TraceProvider = new ConsoleTraceProvider();
context.GetDocument<SkillTestEntity>(entityId);
}
}
示例15: TestDefaultContextGetEntity
public void TestDefaultContextGetEntity()
{
const int entityId = 34;
using (var context = new ElasticsearchContext(ConnectionString, _elasticsearchMappingResolver))
{
context.TraceProvider = new ConsoleTraceProvider();
context.AddUpdateDocument(_entitiesForTests[entityId], entityId);
// Save to Elasticsearch
var ret = context.SaveChanges();
Assert.AreEqual(ret.Status, HttpStatusCode.OK);
// Get the entity
var entityResult = context.GetDocument<SkillTestEntity>(entityId);
Assert.AreEqual(entityResult.Id, entityId);
}
}