Commit 32cec826 by mahaisong

fix:多个index向上封装的完善

parent 32ecdaa1
using System; using System;
...@@ -14,7 +14,7 @@ namespace HTCommon.Data ...@@ -14,7 +14,7 @@ namespace HTCommon.Data
/// </summary> /// </summary>
[Serializable] [Serializable]
[ElasticsearchType(Name = "authors")] [ElasticsearchType(Name = "author")]
public class Author public class Author
{ {
/// <summary> /// <summary>
...@@ -406,7 +406,7 @@ namespace HTCommon.Data ...@@ -406,7 +406,7 @@ namespace HTCommon.Data
/// </summary> /// </summary>
[Serializable] [Serializable]
[ElasticsearchType(Name = "authorrelations")] [ElasticsearchType(Name = "authorrelation")]
public class AuthorRelation public class AuthorRelation
{ {
/// <summary> /// <summary>
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
...@@ -294,6 +294,7 @@ ...@@ -294,6 +294,7 @@
<ItemGroup> <ItemGroup>
<None Include="app.config" /> <None Include="app.config" />
<None Include="packages.config" /> <None Include="packages.config" />
<None Include="ReadMe.md" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project> </Project>
\ No newline at end of file


注意:此类库不允许TestUnit项目之外的使用,因为大量代码为了测试被改动。
需要引用,可以参考其他的解决方案中的Common,推荐palas.common
\ No newline at end of file
D:\smallproject\10.Paul需求-JSON贝格ES导入本地ES\ImportLocalES\HTCommon\bin\Debug\HTCommon.dll.config D:\smallproject\10.Paul需求-JSON贝格ES导入本地ES\ImportLocalES\HTCommon\bin\Debug\HTCommon.dll.config
...@@ -264,6 +264,9 @@ D:\网盘下载\MinderES\MinderES\HTCommon\obj\Debug\HTCommon.csproj.CoreCompile ...@@ -264,6 +264,9 @@ D:\网盘下载\MinderES\MinderES\HTCommon\obj\Debug\HTCommon.csproj.CoreCompile
D:\网盘下载\MinderES\MinderES\HTCommon\obj\Debug\HTCommon.dll D:\网盘下载\MinderES\MinderES\HTCommon\obj\Debug\HTCommon.dll
D:\网盘下载\MinderES\MinderES\HTCommon\obj\Debug\HTCommon.pdb D:\网盘下载\MinderES\MinderES\HTCommon\obj\Debug\HTCommon.pdb
D:\smallproject\10.Paul需求-JSON贝格ES导入本地ES\MinderES\HTCommon\obj\Debug\HTCommon.csprojResolveAssemblyReference.cache D:\smallproject\10.Paul需求-JSON贝格ES导入本地ES\MinderES\HTCommon\obj\Debug\HTCommon.csprojResolveAssemblyReference.cache
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\IKVM.OpenJDK.Nashorn.dll
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\NPOI.OpenXmlFormats.dll
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\NPOI.xml
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\HTCommon.dll.config D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\HTCommon.dll.config
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\HTCommon.dll D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\HTCommon.dll
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\HTCommon.pdb D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\HTCommon.pdb
...@@ -293,7 +296,6 @@ D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\IKVM.OpenJDK ...@@ -293,7 +296,6 @@ D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\IKVM.OpenJDK
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\IKVM.OpenJDK.Media.dll D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\IKVM.OpenJDK.Media.dll
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\IKVM.OpenJDK.Misc.dll D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\IKVM.OpenJDK.Misc.dll
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\IKVM.OpenJDK.Naming.dll D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\IKVM.OpenJDK.Naming.dll
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\IKVM.OpenJDK.Nashorn.dll
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\IKVM.OpenJDK.Remoting.dll D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\IKVM.OpenJDK.Remoting.dll
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\IKVM.OpenJDK.Security.dll D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\IKVM.OpenJDK.Security.dll
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\IKVM.OpenJDK.SwingAWT.dll D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\IKVM.OpenJDK.SwingAWT.dll
...@@ -316,7 +318,6 @@ D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\Newtonsoft.J ...@@ -316,7 +318,6 @@ D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\Newtonsoft.J
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\NPOI.dll D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\NPOI.dll
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\NPOI.OOXML.dll D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\NPOI.OOXML.dll
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\NPOI.OpenXml4Net.dll D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\NPOI.OpenXml4Net.dll
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\NPOI.OpenXmlFormats.dll
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\NPOI.ScratchPad.HWPF.dll D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\NPOI.ScratchPad.HWPF.dll
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\pdfbox-app-2.0.7.dll D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\pdfbox-app-2.0.7.dll
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\ServiceStack.Common.dll D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\ServiceStack.Common.dll
...@@ -339,11 +340,11 @@ D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\Nest.pdb ...@@ -339,11 +340,11 @@ D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\Nest.pdb
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\Nest.xml D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\Nest.xml
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\Nest2_5_8.xml D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\Nest2_5_8.xml
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\Newtonsoft.Json.xml D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\Newtonsoft.Json.xml
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\NPOI.xml
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\ServiceStack.Common.xml D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\ServiceStack.Common.xml
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\ServiceStack.Text.xml D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\ServiceStack.Text.xml
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\zh-Hans\EntityFramework.resources.dll D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\zh-Hans\EntityFramework.resources.dll
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\zh-Hans\EntityFramework.SqlServer.resources.dll D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\zh-Hans\EntityFramework.SqlServer.resources.dll
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\obj\Debug\HTCommon.csprojAssemblyReference.cache
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\obj\Debug\HTCommon.csproj.CoreCompileInputs.cache D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\obj\Debug\HTCommon.csproj.CoreCompileInputs.cache
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\obj\Debug\HTCommon.csproj.CopyComplete D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\obj\Debug\HTCommon.csproj.CopyComplete
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\obj\Debug\HTCommon.dll D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\obj\Debug\HTCommon.dll
......
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
...@@ -6,12 +6,15 @@ ...@@ -6,12 +6,15 @@
<connectionStrings> <connectionStrings>
<!--20187150点迁移完成前保留--> <!--20187150点迁移完成前保留--><!--
<add name="2ESDatabase" connectionString="host=tank.palaspom.com|mech.palaspom.com;port=9200;defaultindex=test_version2;requesttimeout=30000;version=2;" /> <add name="2ESDatabase" connectionString="host=tank.palaspom.com|mech.palaspom.com;port=9200;defaultindex=test_version2;requesttimeout=0:1:00;version=2;" />-->
<add name="2ESDatabase" connectionString="host=127.0.0.1|localhost;port=9200;defaultindex=test;requesttimeout=0:1:00;version=2;" />
<!--(全部小写)6没有defaultindexIndex:palas前缀字符+“_”+type) --> <!--(全部小写)6没有defaultindexIndex:palas前缀字符+“_”+type) -->
<!--<add name="ESDatabase" connectionString="host=tank.palaspom.com|mech.palaspom.com;port=9200;defaultindex=test_version2;requesttimeout=30000;version=2;" />--> <add name="ESDatabase" connectionString="host=minder;port=9200;requesttimeout=0:1:00;version=6;indexprefix=palas_;" />
<add name="ESDatabase" connectionString="host=minder;port=9200;requesttimeout=30000;version=6;indexprefix=palas_;" />
</connectionStrings> </connectionStrings>
......
using Nest; ++ /dev/null
using Nest;
using HTCommon.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace TestES6_2.ES2
{
public class ESAuthorAccess : ESAccess
{
public static Author SearchByAuthorID(String id)
{
SearchDescriptor<Author> builder = new SearchDescriptor<Author>()
.Query(q => q
.Bool(b => b
.Must(m => m
.Term(f => f.AuthorID, id))));
return SearchTop(builder);
}
public static Author[] SearchByNickName(String name, Int32 start = 0, Int32 count = 10)
{
SearchDescriptor<Author> builder = new SearchDescriptor<Author>()
.From(start)
.Size(count)
.Query(q => q
.Bool(b => b
.Must(m => m
.Term(f => f.AuthorName, name)
)
)
);
return Search(builder);
}
public static Author SearchByLocationHistoryTask(DateTime since)
{
//SearchBuilder<Author> builder = new SearchBuilder<Author>();
//builder.Query.Must
// .AddQuery(o => o.Location_NextRefreshTime, ActionType.LessEqual, since)
// .AddQuery(o => o.Location_RefreshStatus, ActionType.Equal, (int)Enums.CrawlStatus.Normal);
//return SearchTop(builder);
try
{
SearchDescriptor<Author> builder = new SearchDescriptor<Author>()
.Size(1)
.Query(q => q
.Bool(b => b
.Must(m => m
.Term(f => f.RefreshStatus, 0)
&& m.DateRange(r => r
.Field(f => f.NextRefreshTime)
.GreaterThan(DateTime.MinValue)
.LessThanOrEquals(DateTime.Now)
)
)
)
);
return ESAccess.SearchTop(builder);
}
catch
{
return null;
}
}
public static Boolean DeleteByAuthorID(String id)
{
//QueryContainer query = new TermQuery()
//{
// Field = Property.Path<Author>(p => p.AuthorID),
// Value = id
//};
//DeleteByQueryRequest<Author> builder = new DeleteByQueryRequest<Author>()
//{
// Query = query
//};
//return Delete(builder);
return false;
}
[Obsolete("使用ESAccess.IndexOrUpdate代替")]
public static Boolean IndexOrUpdate(Author result)
{
return ESAccess.IndexOrUpdate(result);
}
public static String SearchAuthorTag(String resultID)
{
SearchDescriptor<Author> builder = new SearchDescriptor<Author>()
.Source(s => s.Includes(f => f.Field(o => o.Tags)))
.Query(q => q
.Bool(b => b
.Must(m => m
.Term(f => f.AuthorID, resultID)
)
)
);
Author result = SearchTop(builder);
return result == null || result.Tags == null ? String.Empty : String.Join(",", result.Tags);
}
public static AuthorRelation SearchRelation(String followerID, String targetID)
{
SearchDescriptor<AuthorRelation> builder = new SearchDescriptor<AuthorRelation>()
.Query(q => q
.Bool(b => b
.Must(m => m
.Term(f => f.FollowerID, followerID)
&& m.Term(f => f.TargetID, targetID)
)
)
);
return ESAccess.SearchTop(builder);
}
public static Boolean IndexOrUpdateRelation(String followerID, String targetID)
{
SearchDescriptor<AuthorRelation> builder = new SearchDescriptor<AuthorRelation>()
.Query(q => q
.Bool(b => b
.Must(m => m
.Term(f => f.FollowerID, followerID)
&& m.Term(f => f.TargetID, targetID)
)
)
);
Int32 count = ESAccess.Count(builder);
AuthorRelation relation = new AuthorRelation()
{
TargetID = targetID,
FollowerID = followerID,
UpdateTime = DateTime.Now,
IsDeleted = false,
};
if (count > 0)
{
//return ESAuthorUpdateAccess.Update(relation);
return false;
}
else
{
relation.CreateTime = relation.UpdateTime;
return ESAccess.IndexOrUpdate(relation);
}
}
public static Boolean Update(Author result, String id = null)
{
//return ESAuthorUpdateAccess.Update(result, id);
return false;
}
}
}
using Nest; ++ /dev/null
using Nest;
using HTCommon.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestES6_2.ES2
{
public class ESAuthorUpdateAccess
{
//public static Boolean Update(Author author, Action<UpdateScriptBuilder<Author>> scriptBuilder, String id = null)
//{
// if (String.IsNullOrEmpty(id))
// {
// id = GetAuthorIndexID(author);
// if (id == null)
// {
// return false;
// }
// }
// var result = ESUpdateAccess.UpdateSingleCore(id, scriptBuilder);
// if (result == null || result.ServerError != null)
// return false;
// else
// return true;
//}
//public static Boolean Update(Author author, String id = null)
//{
// if (String.IsNullOrEmpty(id))
// {
// id = GetAuthorIndexID(author);
// if (id == null)
// return false;
// }
// var result = ESUpdateAccess.UpdateSingleCore(id, author);
// if (result == null || result.ServerError != null)
// return false;
// else
// return true;
//}
//public static Boolean Update(AuthorRelation relation, String id = null)
//{
// if (String.IsNullOrEmpty(id))
// {
// id = GetAuthorRelationIndexID(relation);
// if (id == null)
// {
// return false;
// }
// }
// var result = ESUpdateAccess.UpdateSingleCore<AuthorRelation>(id, o =>
// {
// o.AddScript<DateTime>(p => p.UpdateTime, UpdateType.Assign, relation.UpdateTime);
// o.AddScript<Boolean>(p => p.IsDeleted, UpdateType.Assign, relation.IsDeleted);
// });
// if (result == null || result.ServerError != null)
// return false;
// else
// return true;
//}
private static String GetAuthorIndexID(Author author)
{
SearchDescriptor<Author> builder = new SearchDescriptor<Author>()
.From(0)
.Size(1)
.Query(q => q
.Bool(b => b
.Must(m => m
.Term(f => f.AuthorID, author.AuthorID)
)
)
);
return ESAccess.SearchESInternalID<Author>(builder);
}
private static String GetAuthorRelationIndexID(AuthorRelation relation)
{
SearchDescriptor<AuthorRelation> builder = new SearchDescriptor<AuthorRelation>()
.Query(q => q
.Bool(b => b
.Must(m => m
.Term(f => f.FollowerID, relation.FollowerID)
&& m.Term(f => f.TargetID, relation.TargetID)
)
)
);
return ESAccess.SearchESInternalID(builder);
}
}
}
using Nest; ++ /dev/null
using Nest;
using HTCommon;
using HTCommon.Data6;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestES6_2.ES2
{
public class ESItemUpdateAccess
{
public static Boolean Update(Item item, Action<UpdateScriptBuilder<Item>> scriptBuilder, String id = null)
{
if (String.IsNullOrEmpty(id))
{
id = GetItemIndexID(item);
if (id == null)
{
return false;
}
}
//var result = ESUpdateAccess.UpdateSingleCore(id, scriptBuilder);
//if (result == null || result.ServerError != null)
// return false;
//else
return true;
}
public static Boolean Update(Item item, String id = null)
{
if (String.IsNullOrEmpty(id))
{
id = GetItemIndexID(item);
if (id == null)
{
return false;
}
}
//var result = ESUpdateAccess.UpdateSingleCore(id, item);
//if (result == null || result.ServerError != null)
// return false;
//else
return true;
}
private static String GetItemIndexID(Item item)
{
SearchDescriptor<Item> builder = new SearchDescriptor<Item>()
.From(0)
.Size(1)
.Query(q => q
.Bool(b => b
.Must(m => m
.Term(f => f.ItemID, item.ItemID)
)
)
);
return ESAccess.SearchESInternalID<Item>(builder);
}
}
}
using Nest; ++ /dev/null
using Nest;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestES6_2.ES2
{
public class ESUpdateAccess
{
//public static IUpdateResponse<T> UpdateSingleCore<T>(String id, Action<UpdateScriptBuilder<T>> scriptBuilder) where T : class
//{
// ElasticClient ec = new ElasticClient(ESClientConfigureManager.ConnectSetting);
// UpdateScriptBuilder<T> builder = new UpdateScriptBuilder<T>();
// scriptBuilder(builder);
// String script = null;
// var func = builder.GetScript(out script);
// Func<UpdateDescriptor<ScriptDescriptor, IScript>> d = new UpdateDescriptor<ScriptDescriptor, IScript>("Index","Type","ID");
// IUpdateResponse<T> resp = ec.Update<T>(id,u => u.Index(id).Script(d).Params(func));
// return resp;
//}
//public static IUpdateResponse<T> UpdateSingleCore<T>(String id, T item) where T : class
//{
// ElasticClient ec = new ElasticClient(ESClientConfigureManager.ConnectSetting);
// return ec.Update<T>(id, o => o
// .Index(id)
// .Doc(item)
// );
//}
//public static IUpdateResponse<T> UpdateBulkCore<T>() where T : class
//{
// return null;
//}
}
}
using Nest; ++ /dev/null
using Nest;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace TestES6_2.ES2
{
/// <summary>
/// Update方法支持三种更新方式, =, +=, -=
/// 日期类型只支持=
/// </summary>
public enum UpdateType
{
/// <summary>
/// =
/// </summary>
Assign = 0,
/// <summary>
/// +=
/// </summary>
Add,
/// <summary>
/// -=
/// </summary>
Subtract,
}
public class UpdateScriptBuilder<T> where T : class
{
private Dictionary<String, Tuple<String, Object>> _maps = new Dictionary<String, Tuple<String, Object>>();
//private PropertyNameResolver resolver = new PropertyNameResolver(ESClientConfigureManager.ConnectSetting);
/// <summary>
/// 只能修改第一级内容,嵌套的内容请写RawScript
/// </summary>
/// <typeparam name="K">修改项的类型</typeparam>
/// <param name="expr">第一级项目的表达式</param>
/// <param name="update">如何修改项目</param>
/// <param name="value">修改值</param>
/// <returns>返回自己,方便嵌套调用</returns>
public UpdateScriptBuilder<T> AddScript<K>(Expression<Func<T, K>> expr, UpdateType update, K value, Boolean resolve = true)
{
if (resolve)
{
//return AddScript(resolver.Resolve(expr), update, value);
return null;
}
else
{
IEnumerable<String> rawExprs = expr.Body.ToString().Split('.').Skip(1);
StringBuilder esExpr = new StringBuilder();
rawExprs.Aggregate(esExpr, (sb, v) =>
{
String esStr = v.Substring(0, 1).ToLower() + v.Substring(1);
(sb.Length > 0 ? sb.Append('.') : sb).Append(esStr);
return sb;
});
return AddScript(esExpr.ToString(), update, value);
}
}
public UpdateScriptBuilder<T> AddScript<K>(String rawExpr, UpdateType update, K value)
{
if (typeof(K) == typeof(DateTime) && update != UpdateType.Assign)
{
throw new ArgumentException("日期类型的更新只支持赋值操作", "update");
}
String updateType = null;
switch (update)
{
case UpdateType.Assign:
updateType = "=";
break;
case UpdateType.Add:
updateType = "+=";
break;
default:
updateType = "-=";
break;
}
Tuple<String, Object> tuple = new Tuple<String, Object>(updateType, value);
_maps[rawExpr] = tuple;
return this;
}
public Func<FluentDictionary<String, Object>, FluentDictionary<String, Object>> GetScript(out String script)
{
List<String> scriptStubs = new List<String>();
Func<FluentDictionary<String, Object>, FluentDictionary<String, Object>> func;
Dictionary<Int32, Object> paramDic = new Dictionary<int, object>();
Int32 vCount = 0;
foreach (var pair in _maps)
{
String left = String.Format("ctx._source.{0}", pair.Key);
paramDic[vCount] = pair.Value.Item2;
scriptStubs.Add(String.Format("{0}{1}value{2}", left, pair.Value.Item1, vCount++));
}
func = f =>
{
foreach (var p in paramDic)
{
f.Add(String.Format("value{0}", p.Key), p.Value);
}
return f;
};
script = String.Join(";", scriptStubs);
return func;
}
}
}
 
...@@ -16,21 +16,27 @@ using System.Threading.Tasks; ...@@ -16,21 +16,27 @@ using System.Threading.Tasks;
namespace TestES6_2.ES6 namespace TestES6_2.ES6
{ {
/// <summary> /// <summary>
/// 直接获取ESData的特殊类 /// 直接获取ESData的Item类型,固定索引、固定类型
/// </summary> /// </summary>
public class ESItemAccess : ESAccess public class ESItemAccess : ESAccess
{ {
public const string NullValue = "空空"; public const string NullValue = "空空";
public static bool DeleteByID(string id) public static bool DeleteByID(string id, string index = null)
{ {
QueryContainer query = new TermQuery() QueryContainer query = new TermQuery()
{ {
Field = "itemID", Field = "itemID",
Value = id Value = id
}; };
string indexStr = index;
if (String.IsNullOrWhiteSpace(indexStr))
{
//es6,必须带前缀
indexStr = ESClientConfigureManager.IndexPrefix + "items";
}
DeleteByQueryRequest<Item> builder = new DeleteByQueryRequest<Item>("palas", "items") DeleteByQueryRequest<Item> builder = new DeleteByQueryRequest<Item>(indexStr, "items")
{ {
Query = query Query = query
}; };
...@@ -38,15 +44,21 @@ namespace TestES6_2.ES6 ...@@ -38,15 +44,21 @@ namespace TestES6_2.ES6
return Delete(builder); return Delete(builder);
} }
public static bool DeleteByCrawlID(string id) public static bool DeleteByCrawlID(string id, string index = null)
{ {
QueryContainer query = new TermQuery() QueryContainer query = new TermQuery()
{ {
Field = "crawlID", Field = "crawlID",
Value = id Value = id
}; };
string indexStr = index;
if (String.IsNullOrWhiteSpace(indexStr))
{
//es6,必须带前缀
indexStr = ESClientConfigureManager.IndexPrefix + "items";
}
DeleteByQueryRequest<Item> builder = new DeleteByQueryRequest<Item>("palas", "items") DeleteByQueryRequest<Item> builder = new DeleteByQueryRequest<Item>(indexStr, "items")
{ {
Query = query Query = query
}; };
...@@ -54,11 +66,11 @@ namespace TestES6_2.ES6 ...@@ -54,11 +66,11 @@ namespace TestES6_2.ES6
return Delete(builder); return Delete(builder);
} }
public static bool Update(Item item) public static bool Update(Item item, string index = null)
{ {
bool isOk = false; bool isOk = false;
isOk = DeleteByID(item.ItemID); isOk = DeleteByID(item.ItemID, index);
isOk = isOk && IndexOrUpdate(item); isOk = isOk && IndexOrUpdate(item, index);
return isOk; return isOk;
} }
...@@ -67,9 +79,9 @@ namespace TestES6_2.ES6 ...@@ -67,9 +79,9 @@ namespace TestES6_2.ES6
/// </summary> /// </summary>
/// <param name="item"></param> /// <param name="item"></param>
[Obsolete("使用ESAccess.IndexOrUpdate代替")] [Obsolete("使用ESAccess.IndexOrUpdate代替")]
public static bool IndexOrUpdateItem(Item value) public static bool IndexOrUpdateItem(Item value, string index = null)
{ {
return IndexOrUpdate(value); return IndexOrUpdate(value, index);
} }
/// <summary> /// <summary>
...@@ -77,7 +89,7 @@ namespace TestES6_2.ES6 ...@@ -77,7 +89,7 @@ namespace TestES6_2.ES6
/// </summary> /// </summary>
/// <param name="id">itemID</param> /// <param name="id">itemID</param>
/// <returns>返回实体</returns> /// <returns>返回实体</returns>
public static Item SearchByItemID(string id) public static Item SearchByItemID(string id, string index = null)
{ {
SearchDescriptor<Item> builder = new SearchDescriptor<Item>() SearchDescriptor<Item> builder = new SearchDescriptor<Item>()
.Size(1) .Size(1)
...@@ -91,7 +103,7 @@ namespace TestES6_2.ES6 ...@@ -91,7 +103,7 @@ namespace TestES6_2.ES6
try try
{ {
return SearchTop(builder); return SearchTop(builder, index);
} }
catch (Exception e) catch (Exception e)
{ {
...@@ -105,7 +117,7 @@ namespace TestES6_2.ES6 ...@@ -105,7 +117,7 @@ namespace TestES6_2.ES6
/// </summary> /// </summary>
/// <param name="id">itemID</param> /// <param name="id">itemID</param>
/// <returns>返回实体</returns> /// <returns>返回实体</returns>
public static Item[] SearchByItemIDs(List<string> itemIds) public static Item[] SearchByItemIDs(List<string> itemIds, string index = null)
{ {
SearchDescriptor<Item> builder = new SearchDescriptor<Item>() SearchDescriptor<Item> builder = new SearchDescriptor<Item>()
.Size(1000) .Size(1000)
...@@ -119,7 +131,7 @@ namespace TestES6_2.ES6 ...@@ -119,7 +131,7 @@ namespace TestES6_2.ES6
try try
{ {
return Search(builder); return Search(builder, index);
} }
catch (Exception e) catch (Exception e)
{ {
...@@ -129,7 +141,7 @@ namespace TestES6_2.ES6 ...@@ -129,7 +141,7 @@ namespace TestES6_2.ES6
} }
[Obsolete("最后抓取条目信息已存在Item的字段中")] [Obsolete("最后抓取条目信息已存在Item的字段中")]
public static LastCrawlInfo GetLastItemInfoByCrawlID(string CrawlID) public static LastCrawlInfo GetLastItemInfoByCrawlID(string CrawlID, string index = null)
{ {
SearchDescriptor<Item> builder = new SearchDescriptor<Item>() SearchDescriptor<Item> builder = new SearchDescriptor<Item>()
.Size(1) .Size(1)
...@@ -144,7 +156,7 @@ namespace TestES6_2.ES6 ...@@ -144,7 +156,7 @@ namespace TestES6_2.ES6
.Descending(f => f.PubDate) .Descending(f => f.PubDate)
); );
var entity = SearchTop(builder); var entity = SearchTop(builder, index);
if (entity == null) if (entity == null)
return null; return null;
...@@ -161,16 +173,16 @@ namespace TestES6_2.ES6 ...@@ -161,16 +173,16 @@ namespace TestES6_2.ES6
/// <param name="searchQuery">查询条件</param> /// <param name="searchQuery">查询条件</param>
/// <typeparam name="T">需要查询的类</typeparam> /// <typeparam name="T">需要查询的类</typeparam>
/// <returns>数据结果</returns> /// <returns>数据结果</returns>
public static T[] Search<T>(SearchDescriptor<T> searchQuery) where T : class public static T[] Search<T>(SearchDescriptor<T> searchQuery,string index=null) where T : class
{ {
ISearchResponse<T> result = SearchDetail(searchQuery); ISearchResponse<T> result = SearchDetail(searchQuery,index);
if (result == null || result.Documents == null) if (result == null || result.Documents == null)
return null; return null;
else else
return result.Documents.ToArray(); return result.Documents.ToArray();
} }
public static void BulkInsert<T>(T[] array) where T : class public static void BulkInsert<T>(T[] array, string index = null) where T : class
{ {
ElasticClient client = new ElasticClient(ESClientConfigureManager.ConnectSetting); ElasticClient client = new ElasticClient(ESClientConfigureManager.ConnectSetting);
...@@ -181,7 +193,7 @@ namespace TestES6_2.ES6 ...@@ -181,7 +193,7 @@ namespace TestES6_2.ES6
var isItem = typeof(T) == typeof(Item); var isItem = typeof(T) == typeof(Item);
if (isItem) if (isItem)
{ {
Parallel.ForEach(array, obj => IndexOrUpdate(obj)); Parallel.ForEach(array, obj => IndexOrUpdate(obj,index));
} }
else else
...@@ -191,7 +203,14 @@ namespace TestES6_2.ES6 ...@@ -191,7 +203,14 @@ namespace TestES6_2.ES6
//} //}
//else //else
{ {
result = client.IndexMany<T>(array); string indexStr = index;
if (String.IsNullOrWhiteSpace(indexStr))
{
//es6,必须带前缀
indexStr = ESClientConfigureManager.IndexPrefix +From(typeof(T));
}
result = client.IndexMany<T>(array, (IndexName)(indexStr));
if (LimitTime.isLimit()) if (LimitTime.isLimit())
{ {
ElasticClient client2 = new ElasticClient(ESClientConfigureManager2.ConnectSetting); ElasticClient client2 = new ElasticClient(ESClientConfigureManager2.ConnectSetting);
...@@ -209,16 +228,24 @@ namespace TestES6_2.ES6 ...@@ -209,16 +228,24 @@ namespace TestES6_2.ES6
} }
public static void BulkInsertTest<T>(T[] array) where T : class public static void BulkInsertTest<T>(T[] array, string index = null) where T : class
{ {
try try
{ {
ElasticClient client = new ElasticClient(ESClientConfigureManager.ConnectSetting); ElasticClient client = new ElasticClient(ESClientConfigureManager.ConnectSetting);
var Descriptor = new BulkDescriptor(); var Descriptor = new BulkDescriptor();
string indexStr = index;
if (String.IsNullOrWhiteSpace(indexStr))
{
//es6,必须带前缀
indexStr = ESClientConfigureManager.IndexPrefix +From(typeof(T));
}
foreach (var Product in array) foreach (var Product in array)
{ {
Descriptor.Index<T>(op => op.Document(Product)); Descriptor.Index<T>(op => op.Document(Product).Index((IndexName)(indexStr)));
} }
client.Bulk(Descriptor); client.Bulk(Descriptor);
if (LimitTime.isLimit()) if (LimitTime.isLimit())
{ {
...@@ -233,9 +260,9 @@ namespace TestES6_2.ES6 ...@@ -233,9 +260,9 @@ namespace TestES6_2.ES6
} }
} }
public static Task BulkInsertAsync<T>(T[] array) where T : class public static Task BulkInsertAsync<T>(T[] array, string index = null) where T : class
{ {
return Task.Run(() => BulkInsert(array)); return Task.Run(() => BulkInsert(array, index));
} }
/// <summary> /// <summary>
...@@ -245,7 +272,7 @@ namespace TestES6_2.ES6 ...@@ -245,7 +272,7 @@ namespace TestES6_2.ES6
/// <param name="value">values</param> /// <param name="value">values</param>
/// <param name="version">the version of index, if use -1, it will ignore the version.</param> /// <param name="version">the version of index, if use -1, it will ignore the version.</param>
/// <returns>the result</returns> /// <returns>the result</returns>
public static IIndexResponse Index<T>(T value, long version = -1, string id = "") where T : class public static IIndexResponse Index<T>(T value, long version = -1, string id = "",string index = null) where T : class
{ {
if (value == null) if (value == null)
{ {
...@@ -269,13 +296,19 @@ namespace TestES6_2.ES6 ...@@ -269,13 +296,19 @@ namespace TestES6_2.ES6
// var item = value as Author; // var item = value as Author;
// id = item.AuthorID; // id = item.AuthorID;
//} //}
string indexStr = index;
if (String.IsNullOrWhiteSpace(indexStr))
{
//es6,必须带前缀
indexStr = ESClientConfigureManager.IndexPrefix +From(typeof(T));
}
if (version < 0) if (version < 0)
result = client.IndexAsync(value, f => f.Id(id)).Result; result = client.IndexAsync(value, f => f.Index((IndexName)(indexStr)).Id(id)).Result;
else if (version == 0) else if (version == 0)
result = client.IndexAsync(value, f => (f.OpType(Elasticsearch.Net.OpType.Create).Id(id))).Result; result = client.IndexAsync(value, f => (f.Index((IndexName)(indexStr)).OpType(Elasticsearch.Net.OpType.Create).Id(id))).Result;
else else
result = client.IndexAsync(value, f => f.Version(version).Id(id)).Result; result = client.IndexAsync(value, f => f.Index((IndexName)(indexStr)).Version(version).Id(id)).Result;
if (LimitTime.isLimit()) if (LimitTime.isLimit())
{ {
...@@ -306,9 +339,9 @@ namespace TestES6_2.ES6 ...@@ -306,9 +339,9 @@ namespace TestES6_2.ES6
/// <typeparam name="T"></typeparam> /// <typeparam name="T"></typeparam>
/// <param name="value"></param> /// <param name="value"></param>
/// <returns></returns> /// <returns></returns>
public static bool IndexOrUpdate<T>(T value, string id = "") where T : class public static bool IndexOrUpdate<T>(T value, string id = "", string index = null) where T : class
{ {
IIndexResponse result = Index(value, -1, id); IIndexResponse result = Index(value, -1, id, index);
if (result == null || result.ServerError != null || result.OriginalException != null) if (result == null || result.ServerError != null || result.OriginalException != null)
{ {
...@@ -328,9 +361,9 @@ namespace TestES6_2.ES6 ...@@ -328,9 +361,9 @@ namespace TestES6_2.ES6
/// <typeparam name="T"></typeparam> /// <typeparam name="T"></typeparam>
/// <param name="value"></param> /// <param name="value"></param>
/// <returns></returns> /// <returns></returns>
public static bool IndexOnly<T>(T value, string id = "") where T : class public static bool IndexOnly<T>(T value, string id = "", string index = null) where T : class
{ {
IIndexResponse result = Index(value, 0, id); IIndexResponse result = Index(value, 0, id, index);
if (result == null || (result.ServerError != null && !result.ServerError.Error.Type.Contains("document_already_exists_exception"))) if (result == null || (result.ServerError != null && !result.ServerError.Error.Type.Contains("document_already_exists_exception")))
return false; return false;
...@@ -345,9 +378,9 @@ namespace TestES6_2.ES6 ...@@ -345,9 +378,9 @@ namespace TestES6_2.ES6
/// <param name="value"></param> /// <param name="value"></param>
/// <param name="id"></param> /// <param name="id"></param>
/// <returns>0 正常插入;1 已存在;2出现异常</returns> /// <returns>0 正常插入;1 已存在;2出现异常</returns>
public static int IndexOnlyDetail<T>(T value, string id = "") where T : class public static int IndexOnlyDetail<T>(T value, string id = "", string index = null) where T : class
{ {
IIndexResponse result = Index(value, 0, id); IIndexResponse result = Index(value, 0, id, index);
if (result == null || (result.ServerError != null && !result.ServerError.Error.Type.Contains("document_already_exists_exception"))) if (result == null || (result.ServerError != null && !result.ServerError.Error.Type.Contains("document_already_exists_exception")))
return 2; return 2;
...@@ -356,7 +389,13 @@ namespace TestES6_2.ES6 ...@@ -356,7 +389,13 @@ namespace TestES6_2.ES6
else else
return 0; return 0;
} }
/// <summary>
/// 警告:参数deleteQuery,必须指定index
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="deleteQuery">警告:参数deleteQuery,必须指定index</param>
/// <returns></returns>
/// <remarks> new Nest.DeleteByQueryRequest<object>("test_index6", "typeitems")</remarks>
public static bool Delete<T>(DeleteByQueryRequest<T> deleteQuery) where T : class public static bool Delete<T>(DeleteByQueryRequest<T> deleteQuery) where T : class
{ {
ElasticClient client = new ElasticClient(ESClientConfigureManager.ConnectSetting); ElasticClient client = new ElasticClient(ESClientConfigureManager.ConnectSetting);
...@@ -374,9 +413,9 @@ namespace TestES6_2.ES6 ...@@ -374,9 +413,9 @@ namespace TestES6_2.ES6
/// <typeparam name="T">查询条件</typeparam> /// <typeparam name="T">查询条件</typeparam>
/// <param name="searchQuery">需要查询的类</param> /// <param name="searchQuery">需要查询的类</param>
/// <returns>数据结果</returns> /// <returns>数据结果</returns>
public static T SearchTop<T>(SearchDescriptor<T> searchQuery) where T : class public static T SearchTop<T>(SearchDescriptor<T> searchQuery, string index = null) where T : class
{ {
var response = Search(searchQuery); var response = Search(searchQuery, index);
if (response == null) if (response == null)
return null; return null;
else else
...@@ -401,17 +440,24 @@ namespace TestES6_2.ES6 ...@@ -401,17 +440,24 @@ namespace TestES6_2.ES6
flagMaintainStop = true; flagMaintainStop = true;
} }
public static int Count<T>(SearchDescriptor<T> searchQuery) where T : class public static int Count<T>(SearchDescriptor<T> searchQuery, string index = null) where T : class
{ {
searchQuery.From(0).Size(0); searchQuery.From(0).Size(0);
var response = SearchDetail(searchQuery); var response = SearchDetail(searchQuery, index);
return Convert.ToInt32(response.Total); return Convert.ToInt32(response.Total);
} }
private static int Count<T>(string jsonQuery) where T : class private static int Count<T>(string jsonQuery, string index = null) where T : class
{ {
ElasticClient client = new ElasticClient(ESClientConfigureManager.ConnectSetting); ElasticClient client = new ElasticClient(ESClientConfigureManager.ConnectSetting);
var response = client.Search<T>(Deserialize<SearchDescriptor<T>>(jsonQuery)); string indexStr = index;
if (String.IsNullOrWhiteSpace(indexStr))
{
//es6,必须带前缀
indexStr = ESClientConfigureManager.IndexPrefix +From(typeof(T));
}
var response = client.Search<T>(Deserialize<SearchDescriptor<T>>(jsonQuery).Index((IndexName)(indexStr)));
return Convert.ToInt32(response.Total); return Convert.ToInt32(response.Total);
} }
...@@ -485,12 +531,24 @@ namespace TestES6_2.ES6 ...@@ -485,12 +531,24 @@ namespace TestES6_2.ES6
/// <param name="searchQuery">查询条件</param> /// <param name="searchQuery">查询条件</param>
/// <typeparam name="T">需要查询的类</typeparam> /// <typeparam name="T">需要查询的类</typeparam>
/// <returns>统计数据结果集</returns> /// <returns>统计数据结果集</returns>
public static ISearchResponse<T> SearchDetail<T>(SearchDescriptor<T> searchQuery) where T : class public static ISearchResponse<T> SearchDetail<T>(SearchDescriptor<T> searchQuery, string index = null) where T : class
{ {
ElasticClient client = new ElasticClient(ESClientConfigureManager.ConnectSetting); ElasticClient client = new ElasticClient(ESClientConfigureManager.ConnectSetting);
ISearchResponse<T> response = null; ISearchResponse<T> response = null;
try try
{ {
if (!String.IsNullOrWhiteSpace(index))
{
searchQuery.Index((IndexName)(index));
}
else
{
//es6,必须带前缀
string indexStr = ESClientConfigureManager.IndexPrefix +From(typeof(T));
searchQuery.Index((IndexName)(indexStr));
}
response = PerformanceUtility.OperationTimedMonitor<ISearchResponse<T>>( response = PerformanceUtility.OperationTimedMonitor<ISearchResponse<T>>(
PerformanceUtility.DefaultTriggerTimeSpan, PerformanceUtility.DefaultTriggerTimeSpan,
PerformanceUtility.DefaultIntervalTimeSpan, PerformanceUtility.DefaultIntervalTimeSpan,
...@@ -520,17 +578,24 @@ namespace TestES6_2.ES6 ...@@ -520,17 +578,24 @@ namespace TestES6_2.ES6
/// <param name="searchQuery">查询条件</param> /// <param name="searchQuery">查询条件</param>
/// <typeparam name="T">需要查询的类</typeparam> /// <typeparam name="T">需要查询的类</typeparam>
/// <returns>统计数据结果集</returns> /// <returns>统计数据结果集</returns>
private static ISearchResponse<T> SearchDetail<T>(string searchQuery) where T : class private static ISearchResponse<T> SearchDetail<T>(string searchQuery, string index = null) where T : class
{ {
ElasticClient client = new ElasticClient(ESClientConfigureManager.ConnectSetting); ElasticClient client = new ElasticClient(ESClientConfigureManager.ConnectSetting);
ISearchResponse<T> response = null; ISearchResponse<T> response = null;
try try
{ {
string indexStr = index;
if (String.IsNullOrWhiteSpace(indexStr))
{
//es6,必须带前缀
indexStr = ESClientConfigureManager.IndexPrefix +From(typeof(T));
}
response = PerformanceUtility.OperationTimedMonitor<ISearchResponse<T>>( response = PerformanceUtility.OperationTimedMonitor<ISearchResponse<T>>(
PerformanceUtility.DefaultTriggerTimeSpan, PerformanceUtility.DefaultTriggerTimeSpan,
PerformanceUtility.DefaultIntervalTimeSpan, PerformanceUtility.DefaultIntervalTimeSpan,
searchQuery, searchQuery,
() => { return client.Search<T>(Deserialize<SearchDescriptor<T>>(searchQuery)); }); () => { return client.Search<T>(Deserialize<SearchDescriptor<T>>(searchQuery).Index((IndexName)(indexStr))); });
var isItem = typeof(T) == typeof(Item); var isItem = typeof(T) == typeof(Item);
if (isItem) if (isItem)
{ {
...@@ -554,10 +619,10 @@ namespace TestES6_2.ES6 ...@@ -554,10 +619,10 @@ namespace TestES6_2.ES6
/// <typeparam name="T"></typeparam> /// <typeparam name="T"></typeparam>
/// <param name="searchQuery"></param> /// <param name="searchQuery"></param>
/// <returns></returns> /// <returns></returns>
public static String SearchESInternalID<T>(SearchDescriptor<T> searchQuery) where T : class public static String SearchESInternalID<T>(SearchDescriptor<T> searchQuery, string index = null) where T : class
{ {
searchQuery.Take(1); searchQuery.Take(1);
var results = SearchDetail(searchQuery); var results = SearchDetail(searchQuery, index);
if (results.HitsMetadata != null && results.HitsMetadata.Hits != null) if (results.HitsMetadata != null && results.HitsMetadata.Hits != null)
{ {
...@@ -571,9 +636,9 @@ namespace TestES6_2.ES6 ...@@ -571,9 +636,9 @@ namespace TestES6_2.ES6
return null; return null;
} }
public static String[] SearchAllESInternalIDs<T>(SearchDescriptor<T> searchQuery) where T : class public static String[] SearchAllESInternalIDs<T>(SearchDescriptor<T> searchQuery, string index = null) where T : class
{ {
var results = SearchDetail(searchQuery); var results = SearchDetail(searchQuery, index);
if (results.HitsMetadata != null && results.HitsMetadata.Hits != null) if (results.HitsMetadata != null && results.HitsMetadata.Hits != null)
{ {
...@@ -605,5 +670,19 @@ namespace TestES6_2.ES6 ...@@ -605,5 +670,19 @@ namespace TestES6_2.ES6
ElasticClient client = new ElasticClient(ESClientConfigureManager.ConnectSetting); ElasticClient client = new ElasticClient(ESClientConfigureManager.ConnectSetting);
return client.RequestResponseSerializer.Deserialize<T>(new MemoryStream(Encoding.UTF8.GetBytes(json))); return client.RequestResponseSerializer.Deserialize<T>(new MemoryStream(Encoding.UTF8.GetBytes(json)));
} }
public static string From(Type type)
{
var attributes = type.GetTypeInfo().GetCustomAttributes(typeof(ElasticsearchTypeAttribute), true);
if (null != attributes && attributes.Length > 0)
{
return ((ElasticsearchTypeAttribute)attributes.First()).Name;
}
else
{
throw new Exception(type.FullName+ "类,没有设置ElasticsearchTypeAttribute标签,无法对应ES中index下的type");
}
}
} }
} }
using Nest; ++ /dev/null
using Nest;
using HTCommon.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace TestES6_2.ES6
{
public class ESAuthorAccess : ESAccess
{
public static Author SearchByAuthorID(String id)
{
SearchDescriptor<Author> builder = new SearchDescriptor<Author>()
.Query(q => q
.Bool(b => b
.Must(m => m
.Term(f => f.AuthorID, id))));
return SearchTop(builder);
}
public static Author[] SearchByNickName(String name, Int32 start = 0, Int32 count = 10)
{
SearchDescriptor<Author> builder = new SearchDescriptor<Author>()
.From(start)
.Size(count)
.Query(q => q
.Bool(b => b
.Must(m => m
.Term(f => f.AuthorName, name)
)
)
);
return Search(builder);
}
public static Author SearchByLocationHistoryTask(DateTime since)
{
//SearchBuilder<Author> builder = new SearchBuilder<Author>();
//builder.Query.Must
// .AddQuery(o => o.Location_NextRefreshTime, ActionType.LessEqual, since)
// .AddQuery(o => o.Location_RefreshStatus, ActionType.Equal, (int)Enums.CrawlStatus.Normal);
//return SearchTop(builder);
try
{
SearchDescriptor<Author> builder = new SearchDescriptor<Author>()
.Size(1)
.Query(q => q
.Bool(b => b
.Must(m => m
.Term(f => f.RefreshStatus, 0)
&& m.DateRange(r => r
.Field(f => f.NextRefreshTime)
.GreaterThan(DateTime.MinValue)
.LessThanOrEquals(DateTime.Now)
)
)
)
);
return ESAccess.SearchTop(builder);
}
catch
{
return null;
}
}
public static Boolean DeleteByAuthorID(String id)
{
//QueryContainer query = new TermQuery()
//{
// Field = Property.Path<Author>(p => p.AuthorID),
// Value = id
//};
//DeleteByQueryRequest<Author> builder = new DeleteByQueryRequest<Author>()
//{
// Query = query
//};
//return Delete(builder);
return false;
}
[Obsolete("使用ESAccess.IndexOrUpdate代替")]
public static Boolean IndexOrUpdate(Author result)
{
return ESAccess.IndexOrUpdate(result);
}
public static String SearchAuthorTag(String resultID)
{
SearchDescriptor<Author> builder = new SearchDescriptor<Author>()
.Source(s => s.Includes(f => f.Field(o => o.Tags)))
.Query(q => q
.Bool(b => b
.Must(m => m
.Term(f => f.AuthorID, resultID)
)
)
);
Author result = SearchTop(builder);
return result == null || result.Tags == null ? String.Empty : String.Join(",", result.Tags);
}
public static AuthorRelation SearchRelation(String followerID, String targetID)
{
SearchDescriptor<AuthorRelation> builder = new SearchDescriptor<AuthorRelation>()
.Query(q => q
.Bool(b => b
.Must(m => m
.Term(f => f.FollowerID, followerID)
&& m.Term(f => f.TargetID, targetID)
)
)
);
return ESAccess.SearchTop(builder);
}
public static Boolean IndexOrUpdateRelation(String followerID, String targetID)
{
SearchDescriptor<AuthorRelation> builder = new SearchDescriptor<AuthorRelation>()
.Query(q => q
.Bool(b => b
.Must(m => m
.Term(f => f.FollowerID, followerID)
&& m.Term(f => f.TargetID, targetID)
)
)
);
Int32 count = ESAccess.Count(builder);
AuthorRelation relation = new AuthorRelation()
{
TargetID = targetID,
FollowerID = followerID,
UpdateTime = DateTime.Now,
IsDeleted = false,
};
if (count > 0)
{
//return ESAuthorUpdateAccess.Update(relation);
return false;
}
else
{
relation.CreateTime = relation.UpdateTime;
return ESAccess.IndexOrUpdate(relation);
}
}
public static Boolean Update(Author result, String id = null)
{
//return ESAuthorUpdateAccess.Update(result, id);
return false;
}
}
}
using Nest; ++ /dev/null
using Nest;
using HTCommon.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestES6_2.ES6
{
public class ESAuthorUpdateAccess
{
//public static Boolean Update(Author author, Action<UpdateScriptBuilder<Author>> scriptBuilder, String id = null)
//{
// if (String.IsNullOrEmpty(id))
// {
// id = GetAuthorIndexID(author);
// if (id == null)
// {
// return false;
// }
// }
// var result = ESUpdateAccess.UpdateSingleCore(id, scriptBuilder);
// if (result == null || result.ServerError != null)
// return false;
// else
// return true;
//}
//public static Boolean Update(Author author, String id = null)
//{
// if (String.IsNullOrEmpty(id))
// {
// id = GetAuthorIndexID(author);
// if (id == null)
// return false;
// }
// var result = ESUpdateAccess.UpdateSingleCore(id, author);
// if (result == null || result.ServerError != null)
// return false;
// else
// return true;
//}
//public static Boolean Update(AuthorRelation relation, String id = null)
//{
// if (String.IsNullOrEmpty(id))
// {
// id = GetAuthorRelationIndexID(relation);
// if (id == null)
// {
// return false;
// }
// }
// var result = ESUpdateAccess.UpdateSingleCore<AuthorRelation>(id, o =>
// {
// o.AddScript<DateTime>(p => p.UpdateTime, UpdateType.Assign, relation.UpdateTime);
// o.AddScript<Boolean>(p => p.IsDeleted, UpdateType.Assign, relation.IsDeleted);
// });
// if (result == null || result.ServerError != null)
// return false;
// else
// return true;
//}
private static String GetAuthorIndexID(Author author)
{
SearchDescriptor<Author> builder = new SearchDescriptor<Author>()
.From(0)
.Size(1)
.Query(q => q
.Bool(b => b
.Must(m => m
.Term(f => f.AuthorID, author.AuthorID)
)
)
);
return ESAccess.SearchESInternalID<Author>(builder);
}
private static String GetAuthorRelationIndexID(AuthorRelation relation)
{
SearchDescriptor<AuthorRelation> builder = new SearchDescriptor<AuthorRelation>()
.Query(q => q
.Bool(b => b
.Must(m => m
.Term(f => f.FollowerID, relation.FollowerID)
&& m.Term(f => f.TargetID, relation.TargetID)
)
)
);
return ESAccess.SearchESInternalID(builder);
}
}
}
using Nest; ++ /dev/null
using Nest;
using HTCommon;
using HTCommon.Data6;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestES6_2.ES6
{
public class ESItemUpdateAccess
{
public static Boolean Update(Item item, Action<UpdateScriptBuilder<Item>> scriptBuilder, String id = null)
{
if (String.IsNullOrEmpty(id))
{
id = GetItemIndexID(item);
if (id == null)
{
return false;
}
}
//var result = ESUpdateAccess.UpdateSingleCore(id, scriptBuilder);
//if (result == null || result.ServerError != null)
// return false;
//else
return true;
}
public static Boolean Update(Item item, String id = null)
{
if (String.IsNullOrEmpty(id))
{
id = GetItemIndexID(item);
if (id == null)
{
return false;
}
}
//var result = ESUpdateAccess.UpdateSingleCore(id, item);
//if (result == null || result.ServerError != null)
// return false;
//else
return true;
}
private static String GetItemIndexID(Item item)
{
SearchDescriptor<Item> builder = new SearchDescriptor<Item>()
.From(0)
.Size(1)
.Query(q => q
.Bool(b => b
.Must(m => m
.Term(f => f.ItemID, item.ItemID)
)
)
);
return ESAccess.SearchESInternalID<Item>(builder);
}
}
}
using Nest; ++ /dev/null
using Nest;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestES6_2.ES6
{
public class ESUpdateAccess
{
//public static IUpdateResponse<T> UpdateSingleCore<T>(String id, Action<UpdateScriptBuilder<T>> scriptBuilder) where T : class
//{
// ElasticClient ec = new ElasticClient(ESClientConfigureManager.ConnectSetting);
// UpdateScriptBuilder<T> builder = new UpdateScriptBuilder<T>();
// scriptBuilder(builder);
// String script = null;
// var func = builder.GetScript(out script);
// Func<UpdateDescriptor<ScriptDescriptor, IScript>> d = new UpdateDescriptor<ScriptDescriptor, IScript>("Index","Type","ID");
// IUpdateResponse<T> resp = ec.Update<T>(id,u => u.Index(id).Script(d).Params(func));
// return resp;
//}
//public static IUpdateResponse<T> UpdateSingleCore<T>(String id, T item) where T : class
//{
// ElasticClient ec = new ElasticClient(ESClientConfigureManager.ConnectSetting);
// return ec.Update<T>(id, o => o
// .Index(id)
// .Doc(item)
// );
//}
//public static IUpdateResponse<T> UpdateBulkCore<T>() where T : class
//{
// return null;
//}
}
}
using Nest; ++ /dev/null
using Nest;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace TestES6_2.ES6
{
/// <summary>
/// Update方法支持三种更新方式, =, +=, -=
/// 日期类型只支持=
/// </summary>
public enum UpdateType
{
/// <summary>
/// =
/// </summary>
Assign = 0,
/// <summary>
/// +=
/// </summary>
Add,
/// <summary>
/// -=
/// </summary>
Subtract,
}
public class UpdateScriptBuilder<T> where T : class
{
private Dictionary<String, Tuple<String, Object>> _maps = new Dictionary<String, Tuple<String, Object>>();
//private PropertyNameResolver resolver = new PropertyNameResolver(ESClientConfigureManager.ConnectSetting);
/// <summary>
/// 只能修改第一级内容,嵌套的内容请写RawScript
/// </summary>
/// <typeparam name="K">修改项的类型</typeparam>
/// <param name="expr">第一级项目的表达式</param>
/// <param name="update">如何修改项目</param>
/// <param name="value">修改值</param>
/// <returns>返回自己,方便嵌套调用</returns>
public UpdateScriptBuilder<T> AddScript<K>(Expression<Func<T, K>> expr, UpdateType update, K value, Boolean resolve = true)
{
if (resolve)
{
//return AddScript(resolver.Resolve(expr), update, value);
return null;
}
else
{
IEnumerable<String> rawExprs = expr.Body.ToString().Split('.').Skip(1);
StringBuilder esExpr = new StringBuilder();
rawExprs.Aggregate(esExpr, (sb, v) =>
{
String esStr = v.Substring(0, 1).ToLower() + v.Substring(1);
(sb.Length > 0 ? sb.Append('.') : sb).Append(esStr);
return sb;
});
return AddScript(esExpr.ToString(), update, value);
}
}
public UpdateScriptBuilder<T> AddScript<K>(String rawExpr, UpdateType update, K value)
{
if (typeof(K) == typeof(DateTime) && update != UpdateType.Assign)
{
throw new ArgumentException("日期类型的更新只支持赋值操作", "update");
}
String updateType = null;
switch (update)
{
case UpdateType.Assign:
updateType = "=";
break;
case UpdateType.Add:
updateType = "+=";
break;
default:
updateType = "-=";
break;
}
Tuple<String, Object> tuple = new Tuple<String, Object>(updateType, value);
_maps[rawExpr] = tuple;
return this;
}
public Func<FluentDictionary<String, Object>, FluentDictionary<String, Object>> GetScript(out String script)
{
List<String> scriptStubs = new List<String>();
Func<FluentDictionary<String, Object>, FluentDictionary<String, Object>> func;
Dictionary<Int32, Object> paramDic = new Dictionary<int, object>();
Int32 vCount = 0;
foreach (var pair in _maps)
{
String left = String.Format("ctx._source.{0}", pair.Key);
paramDic[vCount] = pair.Value.Item2;
scriptStubs.Add(String.Format("{0}{1}value{2}", left, pair.Value.Item1, vCount++));
}
func = f =>
{
foreach (var p in paramDic)
{
f.Add(String.Format("value{0}", p.Key), p.Value);
}
return f;
};
script = String.Join(";", scriptStubs);
return func;
}
}
}
 
...@@ -27,7 +27,7 @@ namespace TestES6_2 ...@@ -27,7 +27,7 @@ namespace TestES6_2
{ {
public const string NullValue = "空空"; public const string NullValue = "空空";
public static bool DeleteByID(string id) public static bool DeleteByID(string id, string index = null)
{ {
if (ESClientConfigureManager.Version == "2") if (ESClientConfigureManager.Version == "2")
{ {
...@@ -35,11 +35,11 @@ namespace TestES6_2 ...@@ -35,11 +35,11 @@ namespace TestES6_2
} }
else else
{ {
return TestES6_2.ES6.ESItemAccess.DeleteByID(id); return TestES6_2.ES6.ESItemAccess.DeleteByID(id, index);
} }
} }
public static bool DeleteByCrawlID(string id) public static bool DeleteByCrawlID(string id, string index = null)
{ {
if (ESClientConfigureManager.Version == "2") if (ESClientConfigureManager.Version == "2")
{ {
...@@ -47,11 +47,11 @@ namespace TestES6_2 ...@@ -47,11 +47,11 @@ namespace TestES6_2
} }
else else
{ {
return TestES6_2.ES6.ESItemAccess.DeleteByCrawlID(id); return TestES6_2.ES6.ESItemAccess.DeleteByCrawlID(id, index);
} }
} }
public static bool Update(Item item) public static bool Update(Item item, string index = null)
{ {
if (ESClientConfigureManager.Version == "2") if (ESClientConfigureManager.Version == "2")
{ {
...@@ -59,7 +59,7 @@ namespace TestES6_2 ...@@ -59,7 +59,7 @@ namespace TestES6_2
} }
else else
{ {
return TestES6_2.ES6.ESItemAccess.Update(item); return TestES6_2.ES6.ESItemAccess.Update(item, index);
} }
} }
...@@ -69,9 +69,9 @@ namespace TestES6_2 ...@@ -69,9 +69,9 @@ namespace TestES6_2
/// </summary> /// </summary>
/// <param name="item"></param> /// <param name="item"></param>
[Obsolete("使用ESAccess.IndexOrUpdate代替")] [Obsolete("使用ESAccess.IndexOrUpdate代替")]
public static bool IndexOrUpdateItem(Item value) public static bool IndexOrUpdateItem(Item value, string index = null)
{ {
return IndexOrUpdate(value); return IndexOrUpdate(value, index);
} }
/// <summary> /// <summary>
...@@ -79,7 +79,7 @@ namespace TestES6_2 ...@@ -79,7 +79,7 @@ namespace TestES6_2
/// </summary> /// </summary>
/// <param name="id">itemID</param> /// <param name="id">itemID</param>
/// <returns>返回实体</returns> /// <returns>返回实体</returns>
public static Item SearchByItemID(string id) public static Item SearchByItemID(string id, string index = null)
{ {
SearchDescriptor<Item> builder = new SearchDescriptor<Item>() SearchDescriptor<Item> builder = new SearchDescriptor<Item>()
.Size(1) .Size(1)
...@@ -93,7 +93,7 @@ namespace TestES6_2 ...@@ -93,7 +93,7 @@ namespace TestES6_2
try try
{ {
return SearchTop(builder); return SearchTop(builder, index);
} }
catch (Exception e) catch (Exception e)
{ {
...@@ -107,7 +107,7 @@ namespace TestES6_2 ...@@ -107,7 +107,7 @@ namespace TestES6_2
/// </summary> /// </summary>
/// <param name="id">itemID</param> /// <param name="id">itemID</param>
/// <returns>返回实体</returns> /// <returns>返回实体</returns>
public static Item[] SearchByItemIDs(List<string> itemIds) public static Item[] SearchByItemIDs(List<string> itemIds, string index = null)
{ {
SearchDescriptor<Item> builder = new SearchDescriptor<Item>() SearchDescriptor<Item> builder = new SearchDescriptor<Item>()
.Size(1000) .Size(1000)
...@@ -121,7 +121,7 @@ namespace TestES6_2 ...@@ -121,7 +121,7 @@ namespace TestES6_2
try try
{ {
return Search(builder); return Search(builder, index);
} }
catch (Exception e) catch (Exception e)
{ {
...@@ -131,7 +131,7 @@ namespace TestES6_2 ...@@ -131,7 +131,7 @@ namespace TestES6_2
} }
[Obsolete("最后抓取条目信息已存在Item的字段中")] [Obsolete("最后抓取条目信息已存在Item的字段中")]
public static LastCrawlInfo GetLastItemInfoByCrawlID(string CrawlID) public static LastCrawlInfo GetLastItemInfoByCrawlID(string CrawlID, string index = null)
{ {
SearchDescriptor<Item> builder = new SearchDescriptor<Item>() SearchDescriptor<Item> builder = new SearchDescriptor<Item>()
.Size(1) .Size(1)
...@@ -146,7 +146,7 @@ namespace TestES6_2 ...@@ -146,7 +146,7 @@ namespace TestES6_2
.Descending(f => f.PubDate) .Descending(f => f.PubDate)
); );
var entity = SearchTop(builder); var entity = SearchTop(builder, index);
if (entity == null) if (entity == null)
return null; return null;
...@@ -163,7 +163,7 @@ namespace TestES6_2 ...@@ -163,7 +163,7 @@ namespace TestES6_2
/// <param name="searchQuery">查询条件</param> /// <param name="searchQuery">查询条件</param>
/// <typeparam name="T">需要查询的类</typeparam> /// <typeparam name="T">需要查询的类</typeparam>
/// <returns>数据结果</returns> /// <returns>数据结果</returns>
public static T[] Search<T>(SearchDescriptor<T> searchQuery) where T : class public static T[] Search<T>(SearchDescriptor<T> searchQuery, string index = null) where T : class
{ {
if (ESClientConfigureManager.Version == "2") if (ESClientConfigureManager.Version == "2")
{ {
...@@ -171,11 +171,11 @@ namespace TestES6_2 ...@@ -171,11 +171,11 @@ namespace TestES6_2
} }
else else
{ {
return TestES6_2.ES6.ESAccess.Search<T>(searchQuery); return TestES6_2.ES6.ESAccess.Search<T>(searchQuery, index);
} }
} }
public static void BulkInsert<T>(T[] array) where T : class public static void BulkInsert<T>(T[] array, string index = null) where T : class
{ {
if (ESClientConfigureManager.Version == "2") if (ESClientConfigureManager.Version == "2")
{ {
...@@ -183,11 +183,11 @@ namespace TestES6_2 ...@@ -183,11 +183,11 @@ namespace TestES6_2
} }
else else
{ {
TestES6_2.ES6.ESAccess.BulkInsert<T>(array); TestES6_2.ES6.ESAccess.BulkInsert<T>(array, index);
} }
} }
public static void BulkInsertTest<T>(T[] array) where T : class public static void BulkInsertTest<T>(T[] array, string index = null) where T : class
{ {
if (ESClientConfigureManager.Version == "2") if (ESClientConfigureManager.Version == "2")
{ {
...@@ -195,10 +195,10 @@ namespace TestES6_2 ...@@ -195,10 +195,10 @@ namespace TestES6_2
} }
else else
{ {
TestES6_2.ES6.ESAccess.BulkInsertTest<T>(array); TestES6_2.ES6.ESAccess.BulkInsertTest<T>(array, index);
} }
} }
public static Task BulkInsertAsync<T>(T[] array) where T : class public static Task BulkInsertAsync<T>(T[] array, string index = null) where T : class
{ {
if (ESClientConfigureManager.Version == "2") if (ESClientConfigureManager.Version == "2")
...@@ -207,7 +207,7 @@ namespace TestES6_2 ...@@ -207,7 +207,7 @@ namespace TestES6_2
} }
else else
{ {
return TestES6_2.ES6.ESAccess.BulkInsertAsync<T>(array); return TestES6_2.ES6.ESAccess.BulkInsertAsync<T>(array, index);
} }
} }
...@@ -218,7 +218,7 @@ namespace TestES6_2 ...@@ -218,7 +218,7 @@ namespace TestES6_2
/// <param name="value">values</param> /// <param name="value">values</param>
/// <param name="version">the version of index, if use -1, it will ignore the version.</param> /// <param name="version">the version of index, if use -1, it will ignore the version.</param>
/// <returns>the result</returns> /// <returns>the result</returns>
public static IIndexResponse Index<T>(T value, long version = -1, string id = "") where T : class public static IIndexResponse Index<T>(T value, long version = -1, string id = "", string index = null) where T : class
{ {
if (ESClientConfigureManager.Version == "2") if (ESClientConfigureManager.Version == "2")
{ {
...@@ -226,7 +226,7 @@ namespace TestES6_2 ...@@ -226,7 +226,7 @@ namespace TestES6_2
} }
else else
{ {
return TestES6_2.ES6.ESAccess.Index<T>(value, version, id); return TestES6_2.ES6.ESAccess.Index<T>(value, version, id, index);
} }
} }
...@@ -237,7 +237,7 @@ namespace TestES6_2 ...@@ -237,7 +237,7 @@ namespace TestES6_2
/// <typeparam name="T"></typeparam> /// <typeparam name="T"></typeparam>
/// <param name="value"></param> /// <param name="value"></param>
/// <returns></returns> /// <returns></returns>
public static bool IndexOrUpdate<T>(T value, string id = "") where T : class public static bool IndexOrUpdate<T>(T value, string id = "", string index = null) where T : class
{ {
if (ESClientConfigureManager.Version == "2") if (ESClientConfigureManager.Version == "2")
{ {
...@@ -245,7 +245,7 @@ namespace TestES6_2 ...@@ -245,7 +245,7 @@ namespace TestES6_2
} }
else else
{ {
return TestES6_2.ES6.ESAccess.IndexOrUpdate<T>(value, id); return TestES6_2.ES6.ESAccess.IndexOrUpdate<T>(value, id, index);
} }
} }
...@@ -255,7 +255,7 @@ namespace TestES6_2 ...@@ -255,7 +255,7 @@ namespace TestES6_2
/// <typeparam name="T"></typeparam> /// <typeparam name="T"></typeparam>
/// <param name="value"></param> /// <param name="value"></param>
/// <returns></returns> /// <returns></returns>
public static bool IndexOnly<T>(T value, string id = "") where T : class public static bool IndexOnly<T>(T value, string id = "", string index = null) where T : class
{ {
if (ESClientConfigureManager.Version == "2") if (ESClientConfigureManager.Version == "2")
{ {
...@@ -263,7 +263,7 @@ namespace TestES6_2 ...@@ -263,7 +263,7 @@ namespace TestES6_2
} }
else else
{ {
return TestES6_2.ES6.ESAccess.IndexOnly<T>(value, id); return TestES6_2.ES6.ESAccess.IndexOnly<T>(value, id, index);
} }
} }
...@@ -275,7 +275,7 @@ namespace TestES6_2 ...@@ -275,7 +275,7 @@ namespace TestES6_2
/// <param name="value"></param> /// <param name="value"></param>
/// <param name="id"></param> /// <param name="id"></param>
/// <returns>0 正常插入;1 已存在;2出现异常</returns> /// <returns>0 正常插入;1 已存在;2出现异常</returns>
public static int IndexOnlyDetail<T>(T value, string id = "") where T : class public static int IndexOnlyDetail<T>(T value, string id = "", string index = null) where T : class
{ {
if (ESClientConfigureManager.Version == "2") if (ESClientConfigureManager.Version == "2")
{ {
...@@ -283,11 +283,11 @@ namespace TestES6_2 ...@@ -283,11 +283,11 @@ namespace TestES6_2
} }
else else
{ {
return TestES6_2.ES6.ESAccess.IndexOnlyDetail<T>(value, id); return TestES6_2.ES6.ESAccess.IndexOnlyDetail<T>(value, id, index);
} }
} }
public static bool Delete<T>(DeleteByQueryRequest<T> deleteQuery) where T : class public static bool Delete<T>(DeleteByQueryRequest<T> deleteQuery, string index = null) where T : class
{ {
if (ESClientConfigureManager.Version == "2") if (ESClientConfigureManager.Version == "2")
{ {
...@@ -306,7 +306,7 @@ namespace TestES6_2 ...@@ -306,7 +306,7 @@ namespace TestES6_2
/// <typeparam name="T">查询条件</typeparam> /// <typeparam name="T">查询条件</typeparam>
/// <param name="searchQuery">需要查询的类</param> /// <param name="searchQuery">需要查询的类</param>
/// <returns>数据结果</returns> /// <returns>数据结果</returns>
public static T SearchTop<T>(SearchDescriptor<T> searchQuery) where T : class public static T SearchTop<T>(SearchDescriptor<T> searchQuery, string index = null) where T : class
{ {
if (ESClientConfigureManager.Version == "2") if (ESClientConfigureManager.Version == "2")
{ {
...@@ -314,7 +314,7 @@ namespace TestES6_2 ...@@ -314,7 +314,7 @@ namespace TestES6_2
} }
else else
{ {
return TestES6_2.ES6.ESAccess.SearchTop<T>(searchQuery); return TestES6_2.ES6.ESAccess.SearchTop<T>(searchQuery, index);
} }
} }
...@@ -342,7 +342,7 @@ namespace TestES6_2 ...@@ -342,7 +342,7 @@ namespace TestES6_2
} }
public static int Count<T>(SearchDescriptor<T> searchQuery) where T : class public static int Count<T>(SearchDescriptor<T> searchQuery, string index = null) where T : class
{ {
if (ESClientConfigureManager.Version == "2") if (ESClientConfigureManager.Version == "2")
{ {
...@@ -350,7 +350,7 @@ namespace TestES6_2 ...@@ -350,7 +350,7 @@ namespace TestES6_2
} }
else else
{ {
return TestES6_2.ES6.ESAccess.Count<T>(searchQuery); return TestES6_2.ES6.ESAccess.Count<T>(searchQuery, index);
} }
} }
...@@ -387,7 +387,7 @@ namespace TestES6_2 ...@@ -387,7 +387,7 @@ namespace TestES6_2
/// <param name="searchQuery">查询条件</param> /// <param name="searchQuery">查询条件</param>
/// <typeparam name="T">需要查询的类</typeparam> /// <typeparam name="T">需要查询的类</typeparam>
/// <returns>统计数据结果集</returns> /// <returns>统计数据结果集</returns>
public static ISearchResponse<T> SearchDetail<T>(SearchDescriptor<T> searchQuery) where T : class public static ISearchResponse<T> SearchDetail<T>(SearchDescriptor<T> searchQuery, string index = null) where T : class
{ {
if (ESClientConfigureManager.Version == "2") if (ESClientConfigureManager.Version == "2")
{ {
...@@ -395,7 +395,7 @@ namespace TestES6_2 ...@@ -395,7 +395,7 @@ namespace TestES6_2
} }
else else
{ {
return TestES6_2.ES6.ESAccess.SearchDetail<T>(searchQuery); return TestES6_2.ES6.ESAccess.SearchDetail<T>(searchQuery, index);
} }
} }
...@@ -406,7 +406,7 @@ namespace TestES6_2 ...@@ -406,7 +406,7 @@ namespace TestES6_2
/// <typeparam name="T"></typeparam> /// <typeparam name="T"></typeparam>
/// <param name="searchQuery"></param> /// <param name="searchQuery"></param>
/// <returns></returns> /// <returns></returns>
public static String SearchESInternalID<T>(SearchDescriptor<T> searchQuery) where T : class public static String SearchESInternalID<T>(SearchDescriptor<T> searchQuery, string index = null) where T : class
{ {
if (ESClientConfigureManager.Version == "2") if (ESClientConfigureManager.Version == "2")
{ {
...@@ -414,11 +414,11 @@ namespace TestES6_2 ...@@ -414,11 +414,11 @@ namespace TestES6_2
} }
else else
{ {
return TestES6_2.ES6.ESAccess.SearchESInternalID<T>(searchQuery); return TestES6_2.ES6.ESAccess.SearchESInternalID<T>(searchQuery, index);
} }
} }
public static String[] SearchAllESInternalIDs<T>(SearchDescriptor<T> searchQuery) where T : class public static String[] SearchAllESInternalIDs<T>(SearchDescriptor<T> searchQuery, string index = null) where T : class
{ {
if (ESClientConfigureManager.Version == "2") if (ESClientConfigureManager.Version == "2")
{ {
...@@ -426,7 +426,7 @@ namespace TestES6_2 ...@@ -426,7 +426,7 @@ namespace TestES6_2
} }
else else
{ {
return TestES6_2.ES6.ESAccess.SearchAllESInternalIDs<T>(searchQuery); return TestES6_2.ES6.ESAccess.SearchAllESInternalIDs<T>(searchQuery, index);
} }
} }
......
using Nest; using Nest;
...@@ -11,17 +11,17 @@ namespace TestES6_2 ...@@ -11,17 +11,17 @@ namespace TestES6_2
{ {
public class ESAuthorAccess : ESAccess public class ESAuthorAccess : ESAccess
{ {
public static Author SearchByAuthorID(String id) public static Author SearchByAuthorID(String id, string index = null)
{ {
SearchDescriptor<Author> builder = new SearchDescriptor<Author>() SearchDescriptor<Author> builder = new SearchDescriptor<Author>()
.Query(q => q .Query(q => q
.Bool(b => b .Bool(b => b
.Must(m => m .Must(m => m
.Term(f => f.AuthorID, id)))); .Term(f => f.AuthorID, id))));
return SearchTop(builder); return SearchTop(builder, index);
} }
public static Author[] SearchByNickName(String name, Int32 start = 0, Int32 count = 10) public static Author[] SearchByNickName(String name, Int32 start = 0, Int32 count = 10, string index = null)
{ {
SearchDescriptor<Author> builder = new SearchDescriptor<Author>() SearchDescriptor<Author> builder = new SearchDescriptor<Author>()
.From(start) .From(start)
...@@ -34,10 +34,10 @@ namespace TestES6_2 ...@@ -34,10 +34,10 @@ namespace TestES6_2
) )
); );
return Search(builder); return Search(builder, index);
} }
public static Author SearchByLocationHistoryTask(DateTime since) public static Author SearchByLocationHistoryTask(DateTime since, string index = null)
{ {
//SearchBuilder<Author> builder = new SearchBuilder<Author>(); //SearchBuilder<Author> builder = new SearchBuilder<Author>();
//builder.Query.Must //builder.Query.Must
...@@ -60,7 +60,7 @@ namespace TestES6_2 ...@@ -60,7 +60,7 @@ namespace TestES6_2
) )
) )
); );
return ESAccess.SearchTop(builder); return ESAccess.SearchTop(builder, index);
} }
catch catch
{ {
...@@ -68,7 +68,7 @@ namespace TestES6_2 ...@@ -68,7 +68,7 @@ namespace TestES6_2
} }
} }
public static Boolean DeleteByAuthorID(String id) public static Boolean DeleteByAuthorID(String id, string index = null)
{ {
//QueryContainer query = new TermQuery() //QueryContainer query = new TermQuery()
//{ //{
...@@ -87,12 +87,12 @@ namespace TestES6_2 ...@@ -87,12 +87,12 @@ namespace TestES6_2
} }
[Obsolete("使用ESAccess.IndexOrUpdate代替")] [Obsolete("使用ESAccess.IndexOrUpdate代替")]
public static Boolean IndexOrUpdate(Author result) public static Boolean IndexOrUpdate(Author result, string index = null)
{ {
return ESAccess.IndexOrUpdate(result); return ESAccess.IndexOrUpdate(result, index);
} }
public static String SearchAuthorTag(String resultID) public static String SearchAuthorTag(String resultID, string index = null)
{ {
SearchDescriptor<Author> builder = new SearchDescriptor<Author>() SearchDescriptor<Author> builder = new SearchDescriptor<Author>()
...@@ -106,11 +106,11 @@ namespace TestES6_2 ...@@ -106,11 +106,11 @@ namespace TestES6_2
); );
Author result = SearchTop(builder); Author result = SearchTop(builder, index);
return result == null || result.Tags == null ? String.Empty : String.Join(",", result.Tags); return result == null || result.Tags == null ? String.Empty : String.Join(",", result.Tags);
} }
public static AuthorRelation SearchRelation(String followerID, String targetID) public static AuthorRelation SearchRelation(String followerID, String targetID, string index = null)
{ {
SearchDescriptor<AuthorRelation> builder = new SearchDescriptor<AuthorRelation>() SearchDescriptor<AuthorRelation> builder = new SearchDescriptor<AuthorRelation>()
.Query(q => q .Query(q => q
...@@ -122,10 +122,10 @@ namespace TestES6_2 ...@@ -122,10 +122,10 @@ namespace TestES6_2
) )
); );
return ESAccess.SearchTop(builder); return ESAccess.SearchTop(builder, index);
} }
public static Boolean IndexOrUpdateRelation(String followerID, String targetID) public static Boolean IndexOrUpdateRelation(String followerID, String targetID, string index = null)
{ {
SearchDescriptor<AuthorRelation> builder = new SearchDescriptor<AuthorRelation>() SearchDescriptor<AuthorRelation> builder = new SearchDescriptor<AuthorRelation>()
.Query(q => q .Query(q => q
...@@ -137,7 +137,7 @@ namespace TestES6_2 ...@@ -137,7 +137,7 @@ namespace TestES6_2
) )
); );
Int32 count = ESAccess.Count(builder); Int32 count = ESAccess.Count(builder, index);
AuthorRelation relation = new AuthorRelation() AuthorRelation relation = new AuthorRelation()
{ {
TargetID = targetID, TargetID = targetID,
...@@ -154,11 +154,11 @@ namespace TestES6_2 ...@@ -154,11 +154,11 @@ namespace TestES6_2
else else
{ {
relation.CreateTime = relation.UpdateTime; relation.CreateTime = relation.UpdateTime;
return ESAccess.IndexOrUpdate(relation); return ESAccess.IndexOrUpdate(relation, index);
} }
} }
public static Boolean Update(Author result, String id = null) public static Boolean Update(Author result, String id = null, string index = null)
{ {
//return ESAuthorUpdateAccess.Update(result, id); //return ESAuthorUpdateAccess.Update(result, id);
return false; return false;
......
using Nest; using Nest;
...@@ -70,7 +70,7 @@ namespace TestES6_2 ...@@ -70,7 +70,7 @@ namespace TestES6_2
// return true; // return true;
//} //}
private static String GetAuthorIndexID(Author author) private static String GetAuthorIndexID(Author author, string index = null)
{ {
SearchDescriptor<Author> builder = new SearchDescriptor<Author>() SearchDescriptor<Author> builder = new SearchDescriptor<Author>()
.From(0) .From(0)
...@@ -83,10 +83,10 @@ namespace TestES6_2 ...@@ -83,10 +83,10 @@ namespace TestES6_2
) )
); );
return ESAccess.SearchESInternalID<Author>(builder); return ESAccess.SearchESInternalID<Author>(builder, index);
} }
private static String GetAuthorRelationIndexID(AuthorRelation relation) private static String GetAuthorRelationIndexID(AuthorRelation relation, string index = null)
{ {
SearchDescriptor<AuthorRelation> builder = new SearchDescriptor<AuthorRelation>() SearchDescriptor<AuthorRelation> builder = new SearchDescriptor<AuthorRelation>()
.Query(q => q .Query(q => q
...@@ -98,7 +98,7 @@ namespace TestES6_2 ...@@ -98,7 +98,7 @@ namespace TestES6_2
) )
); );
return ESAccess.SearchESInternalID(builder); return ESAccess.SearchESInternalID(builder, index);
} }
} }
} }
using Nest; using Nest;
...@@ -11,11 +11,11 @@ namespace TestES6_2 ...@@ -11,11 +11,11 @@ namespace TestES6_2
{ {
public class ESItemUpdateAccess public class ESItemUpdateAccess
{ {
public static Boolean Update(Item item, Action<UpdateScriptBuilder<Item>> scriptBuilder, String id = null) public static Boolean Update(Item item, Action<UpdateScriptBuilder<Item>> scriptBuilder, String id = null, string index = null)
{ {
if (String.IsNullOrEmpty(id)) if (String.IsNullOrEmpty(id))
{ {
id = GetItemIndexID(item); id = GetItemIndexID(item, index);
if (id == null) if (id == null)
{ {
...@@ -31,11 +31,11 @@ namespace TestES6_2 ...@@ -31,11 +31,11 @@ namespace TestES6_2
return true; return true;
} }
public static Boolean Update(Item item, String id = null) public static Boolean Update(Item item, String id = null, string index = null)
{ {
if (String.IsNullOrEmpty(id)) if (String.IsNullOrEmpty(id))
{ {
id = GetItemIndexID(item); id = GetItemIndexID(item, index);
if (id == null) if (id == null)
{ {
...@@ -51,7 +51,7 @@ namespace TestES6_2 ...@@ -51,7 +51,7 @@ namespace TestES6_2
return true; return true;
} }
private static String GetItemIndexID(Item item) private static String GetItemIndexID(Item item, string index = null)
{ {
SearchDescriptor<Item> builder = new SearchDescriptor<Item>() SearchDescriptor<Item> builder = new SearchDescriptor<Item>()
.From(0) .From(0)
...@@ -64,7 +64,7 @@ namespace TestES6_2 ...@@ -64,7 +64,7 @@ namespace TestES6_2
) )
); );
return ESAccess.SearchESInternalID<Item>(builder); return ESAccess.SearchESInternalID<Item>(builder, index);
} }
} }
} }
using System; using HTCommon.Data;
using System; using HTCommon.Data;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Nest;
namespace TestES6_2 namespace TestES6_2
{ {
...@@ -10,7 +12,53 @@ namespace TestES6_2 ...@@ -10,7 +12,53 @@ namespace TestES6_2
{ {
static void Main(string[] args) static void Main(string[] args)
{ {
ESClientConfigureManager es = new ESClientConfigureManager(); //测试语句
// ESClientConfigureManager es = new ESClientConfigureManager();
// SearchDescriptor<HTCommon.Data6.Item> builder6 = new SearchDescriptor<HTCommon.Data6.Item>()
//.Query(q => q.MatchAll());
// var result1 = ESAccess.Search<HTCommon.Data6.Item>(builder6);
// Author model = new Author();
// model.AuthorID = "123123";
// SearchDescriptor<Author> builder2 = new SearchDescriptor<Author>()
// .From(0)
// .Size(1)
// .Query(q => q
// .Bool(b => b
// .Must(m => m
// .Term(f => f.AuthorID, model.AuthorID)
// )
// )
// );
// string result2 = ESAccess.SearchESInternalID<Author>(builder2);
// AuthorRelation relation = new AuthorRelation();
// relation.FollowerID = "xxx";
// relation.TargetID = "yyy";
// SearchDescriptor<AuthorRelation> builder3 = new SearchDescriptor<AuthorRelation>()
// .Query(q => q
// .Bool(b => b
// .Must(m => m
// .Term(f => f.FollowerID, relation.FollowerID)
// && m.Term(f => f.TargetID, relation.TargetID)
// )
// )
// );
// string result3 = ESAccess.SearchESInternalID(builder3);
} }
} }
} }
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
...@@ -63,16 +63,6 @@ ...@@ -63,16 +63,6 @@
<Compile Include="ESClientConfigureManager2.cs" /> <Compile Include="ESClientConfigureManager2.cs" />
<Compile Include="LimitTime.cs" /> <Compile Include="LimitTime.cs" />
<Compile Include="Util\DebugCheck.cs" /> <Compile Include="Util\DebugCheck.cs" />
<Compile Include="ES2\ESAuthorAccess.cs" />
<Compile Include="ES2\ESUpdateAccess\ESAuthorUpdateAccess.cs" />
<Compile Include="ES2\ESUpdateAccess\ESItemUpdateAccess.cs" />
<Compile Include="ES2\ESUpdateAccess\ESUpdateAccess.cs" />
<Compile Include="ES2\ESUpdateAccess\UpdateScriptBuilder.cs" />
<Compile Include="ES6\ESAuthorAccess.cs" />
<Compile Include="ES6\ESUpdateAccess\ESAuthorUpdateAccess.cs" />
<Compile Include="ES6\ESUpdateAccess\ESItemUpdateAccess.cs" />
<Compile Include="ES6\ESUpdateAccess\ESUpdateAccess.cs" />
<Compile Include="ES6\ESUpdateAccess\UpdateScriptBuilder.cs" />
<Compile Include="ESAccess.cs" /> <Compile Include="ESAccess.cs" />
<Compile Include="ESAuthorAccess.cs" /> <Compile Include="ESAuthorAccess.cs" />
<Compile Include="ESClientConfigureManager.cs" /> <Compile Include="ESClientConfigureManager.cs" />
...@@ -89,6 +79,7 @@ ...@@ -89,6 +79,7 @@
<ItemGroup> <ItemGroup>
<None Include="App.config" /> <None Include="App.config" />
<None Include="packages.config" /> <None Include="packages.config" />
<None Include="ReadMe.md" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\HTCommon\HTCommon.csproj"> <ProjectReference Include="..\..\HTCommon\HTCommon.csproj">
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
...@@ -5,10 +5,11 @@ ...@@ -5,10 +5,11 @@
</startup> </startup>
<connectionStrings> <connectionStrings>
<!--20187150点迁移完成前保留--> <!--20187150点迁移完成前保留-->
<add name="2ESDatabase" connectionString="host=tank.palaspom.com|mech.palaspom.com;port=9200;defaultindex=test_version2;requesttimeout=30000;version=2;" /> <!--
<add name="2ESDatabase" connectionString="host=tank.palaspom.com|mech.palaspom.com;port=9200;defaultindex=test_version2;requesttimeout=0:1:00;version=2;" />-->
<add name="2ESDatabase" connectionString="host=127.0.0.1|localhost;port=9200;defaultindex=test;requesttimeout=0:1:00;version=2;" />
<!--(全部小写)6没有defaultindexIndex:palas前缀字符+“_”+type) --> <!--(全部小写)6没有defaultindexIndex:palas前缀字符+“_”+type) -->
<!--<add name="ESDatabase" connectionString="host=tank.palaspom.com|mech.palaspom.com;port=9200;defaultindex=test_version2;requesttimeout=30000;version=2;" />--> <add name="ESDatabase" connectionString="host=minder;port=9200;requesttimeout=0:1:00;version=6;indexprefix=palas_;" />
<add name="ESDatabase" connectionString="host=minder;port=9200;requesttimeout=30000;version=6;indexprefix=palas_;" />
</connectionStrings> </connectionStrings>
<runtime> <runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
......
18661e3d123ed5ef8f1402be73de51c43ad386d8 dbc2ec9cbbd20a6415cd45c9ecb9d03738854590
18661e3d123ed5ef8f1402be73de51c43ad386d8 dbc2ec9cbbd20a6415cd45c9ecb9d03738854590
D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestES6-2\bin\Debug\TestES6-2.exe.config D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestES6-2\bin\Debug\TestES6-2.exe.config
...@@ -45,7 +45,6 @@ D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestES6-2\bin\Debug\Ht ...@@ -45,7 +45,6 @@ D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestES6-2\bin\Debug\Ht
D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestES6-2\bin\Debug\Nest2_5_8.xml D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestES6-2\bin\Debug\Nest2_5_8.xml
D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestES6-2\bin\Debug\NPOI.xml D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestES6-2\bin\Debug\NPOI.xml
D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestES6-2\bin\Debug\Elasticsearch.Net2_5_8.xml D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestES6-2\bin\Debug\Elasticsearch.Net2_5_8.xml
D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestES6-2\obj\Debug\TestES6-2.csprojAssemblyReference.cache
D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestES6-2\obj\Debug\TestES6-2.exe.config D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestES6-2\obj\Debug\TestES6-2.exe.config
D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestES6-2\obj\Debug\TestES6-2.csproj.CoreCompileInputs.cache D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestES6-2\obj\Debug\TestES6-2.csproj.CoreCompileInputs.cache
D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestES6-2\obj\Debug\TestES6-2.csproj.CopyComplete D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestES6-2\obj\Debug\TestES6-2.csproj.CopyComplete
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
...@@ -5,10 +5,11 @@ ...@@ -5,10 +5,11 @@
</startup> </startup>
<connectionStrings> <connectionStrings>
<!--20187150点迁移完成前保留--> <!--20187150点迁移完成前保留-->
<add name="2ESDatabase" connectionString="host=tank.palaspom.com|mech.palaspom.com;port=9200;defaultindex=test_version2;requesttimeout=30000;version=2;" /> <!--
<add name="2ESDatabase" connectionString="host=tank.palaspom.com|mech.palaspom.com;port=9200;defaultindex=test_version2;requesttimeout=0:1:00;version=2;" />-->
<add name="2ESDatabase" connectionString="host=127.0.0.1|localhost;port=9200;defaultindex=test;requesttimeout=0:1:00;version=2;" />
<!--(全部小写)6没有defaultindexIndex:palas前缀字符+“_”+type) --> <!--(全部小写)6没有defaultindexIndex:palas前缀字符+“_”+type) -->
<!--<add name="ESDatabase" connectionString="host=tank.palaspom.com|mech.palaspom.com;port=9200;defaultindex=test_version2;requesttimeout=30000;version=2;" />--> <add name="ESDatabase" connectionString="host=minder;port=9200;requesttimeout=0:1:00;version=6;indexprefix=palas_;" />
<add name="ESDatabase" connectionString="host=minder;port=9200;requesttimeout=30000;version=6;indexprefix=palas_;" />
</connectionStrings> </connectionStrings>
<runtime> <runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
......
 
...@@ -21,6 +21,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTestProject", "..\UnitT ...@@ -21,6 +21,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTestProject", "..\UnitT
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestES6-2", "TestES6-2\TestES6-2.csproj", "{107F4379-D24E-47D6-B4BF-00D49F8F49B7}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestES6-2", "TestES6-2\TestES6-2.csproj", "{107F4379-D24E-47D6-B4BF-00D49F8F49B7}"
EndProject EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "前期测试", "前期测试", "{D6483C25-7140-45A8-9C92-9732997D14EB}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
...@@ -143,6 +145,14 @@ Global ...@@ -143,6 +145,14 @@ Global
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
EndGlobalSection EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{A1ECE553-F7F3-4E6A-AD8B-E1E88D2445CC} = {D6483C25-7140-45A8-9C92-9732997D14EB}
{B4E898CD-73D9-4B8B-B7C4-650851B33BF7} = {D6483C25-7140-45A8-9C92-9732997D14EB}
{17B93E80-9267-4F75-8423-63E5291A3A8F} = {D6483C25-7140-45A8-9C92-9732997D14EB}
{B3B09BBA-6F8E-4D12-BDCC-36BD847C730E} = {D6483C25-7140-45A8-9C92-9732997D14EB}
{4E2ECE6B-5527-4BCB-819C-5387FED6DAC3} = {D6483C25-7140-45A8-9C92-9732997D14EB}
{3FF2A03B-8F84-41C9-9888-2923FEB814D0} = {D6483C25-7140-45A8-9C92-9732997D14EB}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DED7A8C5-FA88-49D7-B047-A0B18BB7D103} SolutionGuid = {DED7A8C5-FA88-49D7-B047-A0B18BB7D103}
EndGlobalSection EndGlobalSection
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
...@@ -4,25 +4,37 @@ ...@@ -4,25 +4,37 @@
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" /> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup> </startup>
<connectionStrings> <connectionStrings>
<!--20187150点迁移完成前保留-->
<add name="2ESDatabase" connectionString="host=127.0.0.1|localhost;port=9200;defaultindex=test;requesttimeout=0:1:00;version=2;" />
<!--(全部小写)6没有defaultindexIndex:palas前缀字符+“_”+type) -->
<add name="ESDatabase" connectionString="host=minder;port=9200;requesttimeout=0:1:00;version=6;indexprefix=test_;" />
</connectionStrings>
<!--<connectionStrings>
<!--<add name="2localESDatabase" connectionString="host=127.0.0.1;port=9200;defaultIndex=test_version2;requesttimeout=30000" />-->
--><!--<add name="2localESDatabase" connectionString="host=127.0.0.1;port=9200;defaultIndex=test_version2;requesttimeout=30000" />--><!--
<!--<add name="2localESDatabase" connectionString="host=minder;port=9200;defaultIndex=test_version6;requesttimeout=30000" />--> --><!--<add name="2localESDatabase" connectionString="host=minder;port=9200;defaultIndex=test_version6;requesttimeout=30000" />--><!--
<add name="6MinderESDatabase" connectionString="host=minder;port=9200;defaultIndex=test_version6;requesttimeout=30000" /> <add name="6MinderESDatabase" connectionString="host=minder;port=9200;defaultIndex=test_version6;requesttimeout=30000" />
<!--<add name="6MinderESDatabase" connectionString="host=127.0.0.1;port=9200;defaultIndex=test_version2;requesttimeout=30000" />--> --><!--<add name="6MinderESDatabase" connectionString="host=127.0.0.1;port=9200;defaultIndex=test_version2;requesttimeout=30000" />--><!--
</connectionStrings> </connectionStrings>-->
<runtime> <runtime>
......
using System;
using System;
using System.Text;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TestES6_2;
namespace UnitTestProject
{
/// <summary>
/// UnitTestES6_2 的摘要说明
/// </summary>
[TestClass]
public class UnitTestES6_2
{
public UnitTestES6_2()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
private TestContext testContextInstance;
/// <summary>
///获取或设置测试上下文,该上下文提供
///有关当前测试运行及其功能的信息。
///</summary>
public TestContext TestContext
{
get
{
return testContextInstance;
}
set
{
testContextInstance = value;
}
}
#region 附加测试特性
//
// 编写测试时,可以使用以下附加特性:
//
// 在运行类中的第一个测试之前使用 ClassInitialize 运行代码
// [ClassInitialize()]
// public static void MyClassInitialize(TestContext testContext) { }
//
// 在类中的所有测试都已运行之后使用 ClassCleanup 运行代码
// [ClassCleanup()]
// public static void MyClassCleanup() { }
//
// 在运行每个测试之前,使用 TestInitialize 来运行代码
// [TestInitialize()]
// public void MyTestInitialize() { }
//
// 在每个测试运行完之后,使用 TestCleanup 来运行代码
// [TestCleanup()]
// public void MyTestCleanup() { }
//
#endregion
[TestMethod]
public void Index()
{
try
{
int i = 52;
HTCommon.Data6.Item item6 = new HTCommon.Data6.Item();
//将数据构造为ITEM。
item6.Crawler = "DeleteTestOracleBeigeNEWS";
//item6.Crawler = "Test_Oracle_Beige_NEWS";
item6.CrawlID = "MA_Test_Oracle_Beige_NEWS";
item6.AuthorName = "test2";
item6.CleanTitle = "test";
item6.ClientItemID = "test";
item6.MediaName = "test";
item6.PubDate = DateTime.Now;
item6.Url = "test";
item6.HTMLText = "test";
item6.FetchTime = DateTime.Now;
item6.CleanText = "test";
item6.Tag = "MinderESFromBeigeOracle";
ESAccess.Index()
item6.ItemID = "test" + i3.ToString();
Nest.IIndexResponse rep1 = client.IndexAsync<HTCommon.Data6.Item>(item6, x => x.Index((IndexName)("test_version2"))).Result;
Nest.IIndexResponse rep2 = client.IndexAsync<HTCommon.Data6.Item>(item6, x => x.Index((IndexName)("test_version6"))).Result;
if (i3 == 99)
{
}
Console.WriteLine("测试完毕");
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
Console.ReadLine();
}
}
}
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
...@@ -91,6 +91,7 @@ ...@@ -91,6 +91,7 @@
<Compile Include="TestES\TestES2\ESItemAccess.cs" /> <Compile Include="TestES\TestES2\ESItemAccess.cs" />
<Compile Include="TestES\TestES6\ES6.cs" /> <Compile Include="TestES\TestES6\ES6.cs" />
<Compile Include="TestES\TestES6\ESClientConfigureManager.cs" /> <Compile Include="TestES\TestES6\ESClientConfigureManager.cs" />
<Compile Include="UnitTestES6-2.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="App.config"> <None Include="App.config">
...@@ -108,6 +109,10 @@ ...@@ -108,6 +109,10 @@
<Project>{3ff2a03b-8f84-41c9-9888-2923feb814d0}</Project> <Project>{3ff2a03b-8f84-41c9-9888-2923feb814d0}</Project>
<Name>TestTwoES2-6</Name> <Name>TestTwoES2-6</Name>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\TestUnit\TestES6-2\TestES6-2.csproj">
<Project>{107f4379-d24e-47d6-b4bf-00d49f8f49b7}</Project>
<Name>TestES6-2</Name>
</ProjectReference>
</ItemGroup> </ItemGroup>
<Choose> <Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'"> <When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
......
95629e2ac04e9d3473c98b5aefb86d1c73a79a7e c7f551447d788877f1be0cc6ad84da21be455cbb
95629e2ac04e9d3473c98b5aefb86d1c73a79a7e c7f551447d788877f1be0cc6ad84da21be455cbb
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment