本文整理汇总了C#中ElasticsearchContext.SearchById方法的典型用法代码示例。如果您正苦于以下问题:C# ElasticsearchContext.SearchById方法的具体用法?C# ElasticsearchContext.SearchById怎么用?C# ElasticsearchContext.SearchById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ElasticsearchContext
的用法示例。
在下文中一共展示了ElasticsearchContext.SearchById方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateGeoShapeCircleMapping
public void CreateGeoShapeCircleMapping()
{
var geoShapeCircleDto = new GeoShapeCircleDto
{
CircleTest = new GeoShapeCircle
{
Coordinates = new GeoPoint(45, 45),
Radius="100m"
},
Id = "1",
Name = "test",
};
using (var context = new ElasticsearchContext(ConnectionString, new ElasticsearchSerializerConfiguration(_elasticsearchMappingResolver)))
{
context.TraceProvider = new ConsoleTraceProvider();
context.IndexCreate<GeoShapeCircleDto>();
Thread.Sleep(1500);
Assert.IsNotNull(context.IndexExists<GeoShapeCircleDto>());
context.AddUpdateDocument(geoShapeCircleDto, geoShapeCircleDto.Id);
context.SaveChanges();
Thread.Sleep(1500);
Assert.AreEqual(1, context.Count<GeoShapeCircleDto>());
var result = context.SearchById<GeoShapeCircleDto>(1);
Assert.AreEqual(geoShapeCircleDto.CircleTest.Coordinates.Count, result.CircleTest.Coordinates.Count);
}
}
示例2: CreateAliasForIndex3
public void CreateAliasForIndex3()
{
var indexAliasDtoTest3 = new IndexAliasDtoTest { Id = 3, Description = "no" };
var indexAliasDtoTest4 = new IndexAliasDtoTest { Id = 4, Description = "boo" };
var indexAliasDtoTest5 = new IndexAliasDtoTest { Id = 5, Description = "boo" };
var aliasParameters = new AliasParameters
{
Actions = new List<AliasBaseParameters>
{
new AliasAddParameters("test4", "indexaliasdtotests")
{
Routing="newroute",
Filter= new TermFilter("description", "boo") // "{ \"term\" : { \"description\" : \"boo\" } }"
}
}
};
const bool userDefinedRouting = true;
var elasticsearchSerializerConfiguration = new ElasticsearchSerializerConfiguration(_elasticsearchMappingResolver,
true, false, userDefinedRouting);
using (var context = new ElasticsearchContext(ConnectionString, elasticsearchSerializerConfiguration))
{
context.AddUpdateDocument(indexAliasDtoTest3, indexAliasDtoTest3.Id, new RoutingDefinition { RoutingId = "newroute" });
context.AddUpdateDocument(indexAliasDtoTest4, indexAliasDtoTest4.Id, new RoutingDefinition { RoutingId = "newroute" });
context.AddUpdateDocument(indexAliasDtoTest5, indexAliasDtoTest5.Id, new RoutingDefinition { RoutingId = "newroute" });
context.SaveChanges();
var result = context.Alias(aliasParameters.ToString());
Assert.IsTrue(result);
Assert.IsTrue(context.AliasExists("test4"));
// using the index
var doc3 = context.GetDocument<IndexAliasDtoTest>(3, new RoutingDefinition {RoutingId = "newroute"});
Assert.IsTrue(doc3.Id == 3);
var doc4 = context.GetDocument<IndexAliasDtoTest>(4, new RoutingDefinition { RoutingId = "newroute" });
Assert.IsTrue(doc4.Id == 4);
}
IElasticsearchMappingResolver elasticsearchMappingResolver = new ElasticsearchMappingResolver();
elasticsearchMappingResolver.AddElasticSearchMappingForEntityType(
typeof(IndexAliasDtoTest),
MappingUtils.GetElasticsearchMapping<IndexAliasDtoTest>("test4", "indexaliasdtotest")
);
using (var context = new ElasticsearchContext(ConnectionString, elasticsearchMappingResolver))
{
// using the alias
var xx = context.GetDocument<IndexAliasDtoTest>(4);
Assert.IsTrue(xx.Id == 4);
// should not be found due to filter
var result = context.SearchById<IndexAliasDtoTest>(3);
Assert.IsNull(result);
}
}
示例3: ReindexTest
public void ReindexTest()
{
var indexAliasDtoTestV1 = new IndexAliasDtoTestThree { Id = 1, Description = "V1" };
var indexAliasDtoTestV2 = new IndexAliasDtoTestThree { Id = 2, Description = "V2" };
IElasticsearchMappingResolver elasticsearchMappingResolverDirectIndex = new ElasticsearchMappingResolver();
IElasticsearchMappingResolver elasticsearchMappingResolverDirectIndexV1 = new ElasticsearchMappingResolver();
var mappingV1 = new IndexAliasDtoTestThreeMappingV1();
IElasticsearchMappingResolver elasticsearchMappingResolverDirectIndexV2 = new ElasticsearchMappingResolver();
var mappingV2 = new IndexAliasDtoTestThreeMappingV2();
elasticsearchMappingResolverDirectIndexV1.AddElasticSearchMappingForEntityType(typeof(IndexAliasDtoTestThree), mappingV1);
elasticsearchMappingResolverDirectIndexV2.AddElasticSearchMappingForEntityType(typeof(IndexAliasDtoTestThree), mappingV2);
// Step 1 create index V1 and add alias
using (var context = new ElasticsearchContext(ConnectionString, elasticsearchMappingResolverDirectIndexV1))
{
// create the index
context.AddUpdateDocument(indexAliasDtoTestV1, indexAliasDtoTestV1.Id);
context.SaveChanges();
var resultCreate = context.AliasCreateForIndex("indexaliasdtotestthrees", "indexaliasdtotestthree_v1");
Assert.IsTrue(resultCreate);
}
// Step 2 create index V2 and replace alias
using (var context = new ElasticsearchContext(ConnectionString, elasticsearchMappingResolverDirectIndexV2))
{
// create the index
context.AddUpdateDocument(indexAliasDtoTestV2, indexAliasDtoTestV2.Id);
context.SaveChanges();
var result = context.AliasReplaceIndex("indexaliasdtotestthrees", "indexaliasdtotestthree_v1", "indexaliasdtotestthree_v2");
Assert.IsTrue(result);
}
Task.Run(() =>
{
using (var context = new ElasticsearchContext(ConnectionString, elasticsearchMappingResolverDirectIndex))
{
while (true)
{
Thread.Sleep(1000);
var itemOk = context.SearchById<IndexAliasDtoTestThree>(2);
if (itemOk != null)
{
_resetEvent.Set();
}
}
}
// ReSharper disable once FunctionNeverReturns
});
WaitForDataOrFail();
// delete index v1
using (var context = new ElasticsearchContext(ConnectionString, elasticsearchMappingResolverDirectIndexV1))
{
context.AllowDeleteForIndex = true;
var thirdDelete = context.DeleteIndexAsync<IndexAliasDtoTestThree>();
thirdDelete.Wait();
}
// delete index v2
using (var context = new ElasticsearchContext(ConnectionString, elasticsearchMappingResolverDirectIndexV2))
{
context.AllowDeleteForIndex = true;
var thirdDelete = context.DeleteIndexAsync<IndexAliasDtoTestThree>();
thirdDelete.Wait();
}
}
示例4: TestsearchByIdNotFound
public void TestsearchByIdNotFound()
{
using (var context = new ElasticsearchContext(ConnectionString, new ElasticsearchSerializerConfiguration(_elasticsearchMappingResolver, SaveChildObjectsAsWellAsParent, ProcessChildDocumentsAsSeparateChildIndex)))
{
context.TraceProvider = new ConsoleTraceProvider();
var childDoc = context.SearchById<ChildDocumentLevelTwo>(767761);
Assert.IsNull(childDoc);
}
}
示例5: TestParentSearchByIdNotFoundWrongType
public void TestParentSearchByIdNotFoundWrongType()
{
using (var context = new ElasticsearchContext(ConnectionString, new ElasticsearchSerializerConfiguration(_elasticsearchMappingResolver, SaveChildObjectsAsWellAsParent, ProcessChildDocumentsAsSeparateChildIndex)))
{
context.TraceProvider = new ConsoleTraceProvider();
var childDoc = context.SearchById<ParentDocument>(71);
Assert.IsNotNull(childDoc);
Assert.AreEqual(7, childDoc.Id);
}
}
示例6: CreateGeoShapePolygonMapping
public void CreateGeoShapePolygonMapping()
{
var geoShapePolygonDto = new GeoShapePolygonDto
{
Coordinates = new GeoShapePolygon
{
Coordinates = new List<List<GeoPoint>>
{
// [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]
new List<GeoPoint>
{
new GeoPoint(100, 0),
new GeoPoint(101, 0),
new GeoPoint(101, 1),
new GeoPoint(100, 1),
new GeoPoint(100, 0)
},
// [ [100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2] ]
new List<GeoPoint>
{
new GeoPoint(100.2, 0.2),
new GeoPoint(100.8, 0.2),
new GeoPoint(100.8, 0.8),
new GeoPoint(100.2, 0.8),
new GeoPoint(100.2, 0.2)
}
}
},
Id = "1",
Name = "test",
};
using (var context = new ElasticsearchContext(ConnectionString, new ElasticsearchSerializerConfiguration(_elasticsearchMappingResolver)))
{
context.TraceProvider = new ConsoleTraceProvider();
context.IndexCreate<GeoShapePolygonDto>();
Thread.Sleep(1500);
Assert.IsNotNull(context.IndexExists<GeoShapePolygonDto>());
context.AddUpdateDocument(geoShapePolygonDto, geoShapePolygonDto.Id);
context.SaveChanges();
Thread.Sleep(1500);
Assert.AreEqual(1,context.Count<GeoShapePolygonDto>());
var result = context.SearchById<GeoShapePolygonDto>(1);
Assert.AreEqual(geoShapePolygonDto.Coordinates.Coordinates.Count, result.Coordinates.Coordinates.Count);
}
}
示例7: TestSearchById
public void TestSearchById()
{
using (var context = new ElasticsearchContext(ConnectionString, new ElasticsearchSerializerConfiguration(_elasticsearchMappingResolver, SaveChildObjectsAsWellAsParent, ProcessChildDocumentsAsSeparateChildIndex, UserDefinedRouting)))
{
context.TraceProvider = new ConsoleTraceProvider();
var childDoc = context.SearchById<ChildDocumentLevelTwoUserDefinedRouting>(71);
Assert.IsNotNull(childDoc);
Assert.AreEqual(71, childDoc.Id);
}
}
开发者ID:jnus,项目名称:ElasticsearchCRUD,代码行数:11,代码来源:OneToNEntitiesSaveWithChildDocumentsTestWithRouting.cs