Commit 6b3c2bb4 by mahaisong

fix:理清设计思路、调试在6的情况下,动态index的方法是否都能正常执行及1000个并发的压力性能。全部通过。

parent c5f64ae8
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,10 +264,12 @@ D:\网盘下载\MinderES\MinderES\HTCommon\obj\Debug\HTCommon.csproj.CoreCompile
D:\网盘下载\MinderES\MinderES\HTCommon\obj\Debug\HTCommon.dll
D:\网盘下载\MinderES\MinderES\HTCommon\obj\Debug\HTCommon.pdb
D:\smallproject\10.Paul需求-JSON贝格ES导入本地ES\MinderES\HTCommon\obj\Debug\HTCommon.csprojResolveAssemblyReference.cache
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\obj\Debug\HTCommon.csproj.CoreCompileInputs.cache
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\Elasticsearch.Net2_5_8.xml
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\Nest.dll
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.pdb
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\Elasticsearch.Net.dll
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\Elasticsearch.Net2_5_8.dll
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\EntityFramework.dll
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\EntityFramework.SqlServer.dll
......@@ -327,11 +329,14 @@ D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\ServiceStack
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\ServiceStack.ServiceInterface.dll
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\ServiceStack.Text.dll
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\Lucene.Net.dll
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\Elasticsearch.Net2_5_8.xml
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\Elasticsearch.Net.pdb
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\Elasticsearch.Net.xml
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\EntityFramework.xml
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\EntityFramework.SqlServer.xml
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\HtmlAgilityPack.pdb
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\HtmlAgilityPack.xml
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\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\NPOI.xml
......@@ -339,13 +344,8 @@ D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\ServiceStack
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.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.CopyComplete
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\obj\Debug\HTCommon.dll
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\obj\Debug\HTCommon.pdb
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\Elasticsearch.Net.dll
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\Nest.dll
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\Elasticsearch.Net.pdb
D:\smallproject\12.ES支持2-6多版本\TestUnit\HTCommon\bin\Debug\Elasticsearch.Net.xml
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\obj\Debug\HTCommon.csprojAssemblyReference.cache
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
......@@ -7,8 +7,14 @@
<connectionStrings>
<add name="ESDatabase" connectionString="host=test_version;port=9200;defaultIndex=test_version6;requesttimeout=30000;provider=2" />
<!--<add name="ESDatabase" connectionString="host=test_version;port=9200;defaultIndex=test_version6;requesttimeout=30000" providerName="6" />
<add name="6MinderESDatabase" connectionString="host=test_version;port=9200;defaultIndex=test_version6;requesttimeout=30000" />
<add name="2localESDatabase" connectionString="host=localhost;port=9200;defaultIndex=test_version2;requesttimeout=30000" />
<add name="2localESDatabase" connectionString="host=localhost;port=9200;defaultIndex=test_version2;requesttimeout=30000" />-->
</connectionStrings>
......
using Elasticsearch.Net;
using Elasticsearch.Net;
......@@ -84,6 +84,8 @@ namespace TestTwoES2_6.ES6_1_0
DefaultIndex = index;
ConnectSetting = new ConnectionSettings(pool).DefaultIndex(index).DisableDirectStreaming();
}
private static String GetValueByName(Dictionary<String, String> nvPair, String name, String defaultValue)
......
using System;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestTwoES2_6.TestBcuzNugError
{
public class ConnectManager
{
// internal const string NameParameterName = "ESDatabase";
// internal const string host = "host"; //可能出现多个链接。 "|"分割。
// internal const string port = "port";
// internal const string defaultIndex = "defaultIndex";
// internal const string provider = "provider";
// // An array to hold the keywords
// internal static readonly string[] ValidKeywords = new[]
// {
// NameParameterName,
// host,
// port,
// defaultIndex,
// provider
// };
// internal const string ProviderConnectionStringParameterName = "provider connection string";
// private const string EntityClientProviderName = "Nest.ElasticClient";
// private readonly object _connectionStringLock = new object();
// private static readonly ESConnectionOptions _emptyConnectionOptions = new ESConnectionOptions(String.Empty, new string[0]);
// private ESConnectionOptions _userConnectionOptions;
// private ESConnectionOptions _effectiveConnectionOptions;
// public ConnectManager(string connectionString)
// {
// ChangeConnectionString(connectionString);
// }
////[SuppressMessage("Microsoft.Design", "CA1065:DoNotRaiseExceptionsInUnexpectedLocations")]
// public string ConnectionString
// {
// get
// {
// if (_userConnectionOptions == null)
// {
// return "连接字符串为空。";
// }
// var userConnectionString = _userConnectionOptions.UsersConnectionString;
// return userConnectionString;
// }
// set
// {
// ChangeConnectionString(value);
// }
// }
// private void ChangeConnectionString(string newConnectionString)
// {
// var userConnectionOptions = _emptyConnectionOptions;
// if (!String.IsNullOrEmpty(newConnectionString))
// {
// userConnectionOptions = new ESConnectionOptions(newConnectionString, ValidKeywords);
// }
// if (!userConnectionOptions.IsEmpty)
// {
// // Find the named connection from the configuration, then extract the settings
// var setting = ConfigurationManager.ConnectionStrings[namedConnection];
// effectiveConnectionOptions = new ESConnectionOptions(
// setting.ConnectionString, ValidKeywords);
// ValidateValueForTheKeyword(effectiveConnectionOptions,MetadataParameterName);
// var providerName = ValidateValueForTheKeyword(
// effectiveConnectionOptions, ESConnectionStringBuilder.ProviderParameterName);
// // Get the correct provider factory
// factory = DbConfiguration.DependencyResolver.GetService<DbProviderFactory>(providerName);
// // Create the underlying provider specific connection and give it the connection string from the ESConnectionOptions object
// storeConnection = GetStoreConnection(factory);
// try
// {
// // When the value of 'Provider Connection String' is null, it means it has not been present in the entity connection string at all.
// // Providers should still be able handle empty connection strings since those may be explicitly passed by clients.
// var providerConnectionString =
// effectiveConnectionOptions[ESConnectionStringBuilder.ProviderConnectionStringParameterName];
// if (providerConnectionString != null)
// {
// DbInterception.Dispatch.Connection.SetConnectionString(
// storeConnection,
// new DbConnectionPropertyInterceptionContext<string>(InterceptionContext).WithValue(providerConnectionString));
// }
// }
// catch (Exception e)
// {
// if (e.IsCatchableExceptionType())
// {
// throw new EntityException(Strings.EntityClient_ProviderSpecificError(@"ConnectionString"), e);
// }
// throw;
// }
// }
// // This lock is to ensure that the connection string matches with the provider connection and metadata workspace that's being
// // managed by this EntityConnection, so states in this connection object are not messed up.
// // It's not for security, but just to help reduce user error.
// lock (_connectionStringLock)
// {
// // Now we have sufficient information and verified the configuration string is good, use them for this connection object
// // Failure should not occur from this point to the end of this method
// _providerFactory = factory;
// _metadataWorkspace = null;
// ClearTransactions();
// UnsubscribeFromStoreConnectionStateChangeEvents();
// _storeConnection = storeConnection;
// SubscribeToStoreConnectionStateChangeEvents();
// // Remembers the connection options objects with the connection string set by the user
// _userConnectionOptions = userConnectionOptions;
// _effectiveConnectionOptions = effectiveConnectionOptions;
// }
// }
// private static string ValidateValueForTheKeyword(
// ESConnectionOptions effectiveConnectionOptions,
// string keywordName)
// {
// var keywordValue = effectiveConnectionOptions[keywordName];
// if (!string.IsNullOrEmpty(keywordValue))
// {
// keywordValue = keywordValue.Trim(); // be nice to user, always trim the value
// }
// // Check that we have a non-null and non-empty value for the keyword
// if (string.IsNullOrEmpty(keywordValue))
// {
// throw new ArgumentException("字符串中KEY" + keywordName + "报错");
// }
// return keywordValue;
// }
}
}
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestTwoES2_6.TestBcuzNugError
{
internal class DebugCheck
{
[Conditional("DEBUG")]
public static void NotNull<T>(T value) where T : class
{
Debug.Assert(value != null);
}
[Conditional("DEBUG")]
public static void NotNull<T>(T? value) where T : struct
{
Debug.Assert(value != null);
}
[Conditional("DEBUG")]
public static void NotEmpty(string value)
{
Debug.Assert(!string.IsNullOrWhiteSpace(value));
}
}
}
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestTwoES2_6.TestBcuzNugError
{
internal class ESConnectionOptions
{
private readonly string _usersConnectionString;
private readonly Dictionary<string, string> _parsetable = new Dictionary<string, string>();
internal readonly NameValuePair KeyChain;
internal ESConnectionOptions()
{
}
internal ESConnectionOptions(string connectionString, IList<string> validKeywords)
{
DebugCheck.NotNull(validKeywords);
_usersConnectionString = connectionString ?? "";
// 解析、初始语法检查
if (0 < _usersConnectionString.Length)
{
KeyChain = ParseInternal(_parsetable, _usersConnectionString, validKeywords);
}
}
internal string UsersConnectionString
{
get { return _usersConnectionString ?? string.Empty; }
}
internal bool IsEmpty
{
get { return (null == KeyChain); }
}
//解析表
internal Dictionary<string, string> Parsetable
{
get { return _parsetable; }
}
internal virtual string this[string keyword]
{
get
{
string value;
_parsetable.TryGetValue(keyword, out value);
return value;
}
}
//[SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase")]
private static string GetKeyName(StringBuilder buffer)
{
var count = buffer.Length;
while ((0 < count)
&& Char.IsWhiteSpace(buffer[count - 1]))
{
count--; //尾部空格
}
return buffer.ToString(0, count).ToLowerInvariant();
}
private static string GetKeyValue(StringBuilder buffer, bool trimWhitespace)
{
var count = buffer.Length;
var index = 0;
if (trimWhitespace)
{
while ((index < count)
&& Char.IsWhiteSpace(buffer[index]))
{
index++; //头部空格
}
while ((0 < count)
&& Char.IsWhiteSpace(buffer[count - 1]))
{
count--; //尾部空格
}
}
return buffer.ToString(index, count - index);
}
// 用于解析的传递状态
private enum ParserState
{
NothingYet = 1, //开始指针
Key,
KeyEqual,
KeyEnd,
UnquotedValue,
DoubleQuoteValue,
DoubleQuoteValueQuote,
SingleQuoteValue,
SingleQuoteValueQuote,
QuotedValueEnd,
NullTermination,
};
//[SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
private static int GetKeyValuePair(
string connectionString, int currentPosition, StringBuilder buffer, out string keyname, out string keyvalue)
{
var startposition = currentPosition;
buffer.Length = 0;
keyname = null;
keyvalue = null;
var currentChar = '\0';
var parserState = ParserState.NothingYet;
var length = connectionString.Length;
for (; currentPosition < length; ++currentPosition)
{
currentChar = connectionString[currentPosition];
switch (parserState)
{
case ParserState.NothingYet: // [\\s;]*
if ((';' == currentChar)
|| Char.IsWhiteSpace(currentChar))
{
continue;
}
if ('\0' == currentChar)
{
parserState = ParserState.NullTermination;
continue;
}
if (Char.IsControl(currentChar))
{
throw new ArgumentException("链接字符串在" + startposition + "位置,报错");
}
startposition = currentPosition;
if ('=' != currentChar)
{
parserState = ParserState.Key;
break;
}
else
{
parserState = ParserState.KeyEqual;
continue;
}
case ParserState.Key: // (?<key>([^=\\s\\p{Cc}]|\\s+[^=\\s\\p{Cc}]|\\s+==|==)+)
if ('=' == currentChar)
{
parserState = ParserState.KeyEqual;
continue;
}
if (Char.IsWhiteSpace(currentChar))
{
break;
}
if (Char.IsControl(currentChar))
{
throw new ArgumentException("链接字符串在"+startposition+"位置,报错");
}
break;
case ParserState.KeyEqual: // \\s*=(?!=)\\s*
if ('=' == currentChar)
{
parserState = ParserState.Key;
break;
}
keyname = GetKeyName(buffer);
if (string.IsNullOrEmpty(keyname))
{
throw new ArgumentException("链接字符串在" + startposition + "位置,报错");
}
buffer.Length = 0;
parserState = ParserState.KeyEnd;
goto case ParserState.KeyEnd;
case ParserState.KeyEnd:
if (Char.IsWhiteSpace(currentChar))
{
continue;
}
if ('\'' == currentChar)
{
parserState = ParserState.SingleQuoteValue;
continue;
}
if ('"' == currentChar)
{
parserState = ParserState.DoubleQuoteValue;
continue;
}
if (';' == currentChar)
{
goto ParserExit;
}
if ('\0' == currentChar)
{
goto ParserExit;
}
if (Char.IsControl(currentChar))
{
throw new ArgumentException("链接字符串在" + startposition + "位置,报错");
}
parserState = ParserState.UnquotedValue;
break;
case ParserState.UnquotedValue: // "((?![\"'\\s])" + "([^;\\s\\p{Cc}]|\\s+[^;\\s\\p{Cc}])*" + "(?<![\"']))"
if (Char.IsWhiteSpace(currentChar))
{
break;
}
if (Char.IsControl(currentChar)
|| ';' == currentChar)
{
goto ParserExit;
}
break;
case ParserState.DoubleQuoteValue: // "(\"([^\"\u0000]|\"\")*\")"
if ('"' == currentChar)
{
parserState = ParserState.DoubleQuoteValueQuote;
continue;
}
if ('\0' == currentChar)
{
throw new ArgumentException("链接字符串在" + startposition + "位置,报错");
}
break;
case ParserState.DoubleQuoteValueQuote:
if ('"' == currentChar)
{
parserState = ParserState.DoubleQuoteValue;
break;
}
keyvalue = GetKeyValue(buffer, false);
parserState = ParserState.QuotedValueEnd;
goto case ParserState.QuotedValueEnd;
case ParserState.SingleQuoteValue: // "('([^'\u0000]|'')*')"
if ('\'' == currentChar)
{
parserState = ParserState.SingleQuoteValueQuote;
continue;
}
if ('\0' == currentChar)
{
throw new ArgumentException("链接字符串在" + startposition + "位置,报错");
}
break;
case ParserState.SingleQuoteValueQuote:
if ('\'' == currentChar)
{
parserState = ParserState.SingleQuoteValue;
break;
}
keyvalue = GetKeyValue(buffer, false);
parserState = ParserState.QuotedValueEnd;
goto case ParserState.QuotedValueEnd;
case ParserState.QuotedValueEnd:
if (Char.IsWhiteSpace(currentChar))
{
continue;
}
if (';' == currentChar)
{
goto ParserExit;
}
if ('\0' == currentChar)
{
parserState = ParserState.NullTermination;
continue;
}
throw new ArgumentException("链接字符串在" + startposition + "位置,报错"); // unbalanced single quote
case ParserState.NullTermination: // [\\s;\u0000]*
if ('\0' == currentChar)
{
continue;
}
if (Char.IsWhiteSpace(currentChar))
{
continue;
}
throw new ArgumentException("链接字符串在" + startposition + "位置,报错");
default:
throw new InvalidOperationException("链接字符串在" + startposition + "位置,报错");
}
buffer.Append(currentChar);
}
ParserExit:
switch (parserState)
{
case ParserState.Key:
case ParserState.DoubleQuoteValue:
case ParserState.SingleQuoteValue:
throw new ArgumentException("链接字符串在"+startposition+"位置,报错");
case ParserState.KeyEqual:
keyname = GetKeyName(buffer);
if (string.IsNullOrEmpty(keyname))
{
throw new ArgumentException("链接字符串在"+startposition+"位置,报错");
}
break;
case ParserState.UnquotedValue:
keyvalue = GetKeyValue(buffer, true);
var tmpChar = keyvalue[keyvalue.Length - 1];
if (('\'' == tmpChar)
|| ('"' == tmpChar))
{
throw new ArgumentException("链接字符串在"+startposition+"位置,报错");
}
break;
case ParserState.DoubleQuoteValueQuote:
case ParserState.SingleQuoteValueQuote:
case ParserState.QuotedValueEnd:
keyvalue = GetKeyValue(buffer, false);
break;
case ParserState.NothingYet:
case ParserState.KeyEnd:
case ParserState.NullTermination:
break;
default:
throw new InvalidOperationException(
"链接字符串在" + startposition + "位置,报错");
}
if ((';' == currentChar)
&& (currentPosition < connectionString.Length))
{
currentPosition++;
}
return currentPosition;
}
private static NameValuePair ParseInternal(IDictionary<string, string> parsetable, string connectionString, IList<string> validKeywords)
{
DebugCheck.NotNull(connectionString);
DebugCheck.NotNull(validKeywords);
var buffer = new StringBuilder();
NameValuePair localKeychain = null, keychain = null;
var nextStartPosition = 0;
var endPosition = connectionString.Length;
while (nextStartPosition < endPosition)
{
var startPosition = nextStartPosition;
string keyname, keyvalue;
nextStartPosition = GetKeyValuePair(connectionString, startPosition, buffer, out keyname, out keyvalue);
if (string.IsNullOrEmpty(keyname))
{
break;
}
if (!validKeywords.Contains(keyname))
{
throw new ArgumentException("字符串中KEY" + keyname + "报错");
}
parsetable[keyname] = keyvalue; // 最后一个键值对获胜(或第一个)
if (null != localKeychain)
{
localKeychain = localKeychain.Next = new NameValuePair();
}
else
{
keychain = localKeychain = new NameValuePair();
}
}
return keychain;
}
}
}
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestTwoES2_6.TestBcuzNugError
{
internal sealed class NameValuePair
{
private NameValuePair _next;
internal NameValuePair Next
{
get { return _next; }
set
{
if ((null != _next)
|| (null == value))
{
throw new InvalidOperationException("");
}
_next = value;
}
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
......@@ -90,6 +90,10 @@
<Compile Include="PerformanceUtility.cs" />
<Compile Include="Program1.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TestBcuzNugError\ConnectManager.cs" />
<Compile Include="TestBcuzNugError\ESConnectionOptions.cs" />
<Compile Include="TestBcuzNugError\DebugCheck.cs" />
<Compile Include="TestBcuzNugError\NameValuePair.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config">
......
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
......@@ -7,8 +7,14 @@
<connectionStrings>
<add name="ESDatabase" connectionString="host=test_version;port=9200;defaultIndex=test_version6;requesttimeout=30000;provider=2" />
<!--<add name="ESDatabase" connectionString="host=test_version;port=9200;defaultIndex=test_version6;requesttimeout=30000" providerName="6" />
<add name="6MinderESDatabase" connectionString="host=test_version;port=9200;defaultIndex=test_version6;requesttimeout=30000" />
<add name="2localESDatabase" connectionString="host=localhost;port=9200;defaultIndex=test_version2;requesttimeout=30000" />
<add name="2localESDatabase" connectionString="host=localhost;port=9200;defaultIndex=test_version2;requesttimeout=30000" />-->
</connectionStrings>
......
043d87f8d664dffcb652a9a10e582f84240a0a79
cfc6e0ba14a8310895a1f631576e0913083f7176
043d87f8d664dffcb652a9a10e582f84240a0a79
cfc6e0ba14a8310895a1f631576e0913083f7176
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
\ No newline at end of file
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestES6_2
{
class Program
{
static void Main(string[] args)
{
}
}
}
using System.Reflection;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("TestES6-2")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TestES6-2")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("107f4379-d24e-47d6-b4bf-00d49f8f49b7")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
// 方法是按如下所示使用“*”: :
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{107F4379-D24E-47D6-B4BF-00D49F8F49B7}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>TestES6_2</RootNamespace>
<AssemblyName>TestES6-2</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
++ "b/12.ES\346\224\257\346\214\2012-6\345\244\232\347\211\210\346\234\254/TestUnit/TestUnit/TestES6-2/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs"
++ "b/12.ES\346\224\257\346\214\2012-6\345\244\232\347\211\210\346\234\254/TestUnit/TestUnit/TestES6-2/obj/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs"
++ "b/12.ES\346\224\257\346\214\2012-6\345\244\232\347\211\210\346\234\254/TestUnit/TestUnit/TestES6-2/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs"
02d941efbc43fafdca26cfd3c70cc077be835e19
02d941efbc43fafdca26cfd3c70cc077be835e19


......@@ -9,9 +9,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elasticsearch.Net2_5_8", ".
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nest2_5_8", "..\elasticsearch-net-2.5.8\src\Nest\Nest2_5_8.csproj", "{17B93E80-9267-4F75-8423-63E5291A3A8F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Elasticsearch.Net", "..\elasticsearch-net-6.1.0\src\Elasticsearch.Net\Elasticsearch.Net.csproj", "{B3B09BBA-6F8E-4D12-BDCC-36BD847C730E}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Elasticsearch.Net", "..\elasticsearch-net-6.1.0\src\Elasticsearch.Net\Elasticsearch.Net.csproj", "{B3B09BBA-6F8E-4D12-BDCC-36BD847C730E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nest", "..\elasticsearch-net-6.1.0\src\Nest\Nest.csproj", "{4E2ECE6B-5527-4BCB-819C-5387FED6DAC3}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Nest", "..\elasticsearch-net-6.1.0\src\Nest\Nest.csproj", "{4E2ECE6B-5527-4BCB-819C-5387FED6DAC3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HTCommon", "..\HTCommon\HTCommon.csproj", "{E497051E-61E1-4247-93D3-7929A8C8B7F6}"
EndProject
......@@ -19,6 +19,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestTwoES2-6", "..\TestTwoE
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTestProject", "..\UnitTestProject\UnitTestProject.csproj", "{CCBB6A99-9FB1-441C-AE3B-B406A2A26DD9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestES6-2", "TestES6-2\TestES6-2.csproj", "{107F4379-D24E-47D6-B4BF-00D49F8F49B7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
......@@ -125,6 +127,18 @@ Global
{CCBB6A99-9FB1-441C-AE3B-B406A2A26DD9}.Release|x64.Build.0 = Release|Any CPU
{CCBB6A99-9FB1-441C-AE3B-B406A2A26DD9}.Release|x86.ActiveCfg = Release|Any CPU
{CCBB6A99-9FB1-441C-AE3B-B406A2A26DD9}.Release|x86.Build.0 = Release|Any CPU
{107F4379-D24E-47D6-B4BF-00D49F8F49B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{107F4379-D24E-47D6-B4BF-00D49F8F49B7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{107F4379-D24E-47D6-B4BF-00D49F8F49B7}.Debug|x64.ActiveCfg = Debug|Any CPU
{107F4379-D24E-47D6-B4BF-00D49F8F49B7}.Debug|x64.Build.0 = Debug|Any CPU
{107F4379-D24E-47D6-B4BF-00D49F8F49B7}.Debug|x86.ActiveCfg = Debug|Any CPU
{107F4379-D24E-47D6-B4BF-00D49F8F49B7}.Debug|x86.Build.0 = Debug|Any CPU
{107F4379-D24E-47D6-B4BF-00D49F8F49B7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{107F4379-D24E-47D6-B4BF-00D49F8F49B7}.Release|Any CPU.Build.0 = Release|Any CPU
{107F4379-D24E-47D6-B4BF-00D49F8F49B7}.Release|x64.ActiveCfg = Release|Any CPU
{107F4379-D24E-47D6-B4BF-00D49F8F49B7}.Release|x64.Build.0 = Release|Any CPU
{107F4379-D24E-47D6-B4BF-00D49F8F49B7}.Release|x86.ActiveCfg = Release|Any CPU
{107F4379-D24E-47D6-B4BF-00D49F8F49B7}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
......@@ -7,17 +7,17 @@
<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="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" />-->
......
using System;
using System;
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using HTCommon.Data;
using Nest2_5_8;
//using Nest2_5_8;
using Nest;
namespace UnitTestProject.TestES.TestES2
......@@ -119,6 +119,21 @@ namespace UnitTestProject.TestES.TestES2
[TestMethod]
public void Search()
{
//动态index测试
//var node = new Uri("http://minder:9200");
//var settings = new ConnectionSettings(node);
//var client = new ElasticClient(settings);
//client.Search<HTCommon.Data6.Item>();
// Nest.SearchDescriptor<HTCommon.Data6.Item> builder2 = new Nest.SearchDescriptor<HTCommon.Data6.Item>()
// .Query(q => q.MatchAll()).Index((Indices)typeof(HTCommon.Data6.Item));
//// Nest.ISearchResponse<> rep2 =
//内部调用 SearchDetail
......
using System;
using System;
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using HTCommon.Data;
using Nest;
namespace UnitTestProject.TestES
{
//注意,defaultIndex是null时,不指定index会报错、异常。
//写错了会爆404.
//某种查询,是自己写的语句查询的,能不能切换。 即,在拥有默认的情况下依然可以查询其他index。 如果以后是6的话,最好限制使用,必须带有index才行。
//(怎么才能打标记,要求NEST为6的情况下,所有的调用都必须加入index指定才行?不默认。不现实。你的接口是必须要默认的。最终:根据类型来吧,不论默认不默认。)
//所以一定要默认。 对于ES2 默认的必须是真名,而不是别名。因为是在代码里面默认。
//或者es2就直接使用defaultIndex, es6就没有。
//本测试类执行的前提,是干掉了defaultIndex的固定值。
//同时测试各个函数在指定index(palas_TName)的情况下,方法是否正常执行。
//同时测试,使用动态index,在ES2中是否能够执行。
//如果通过。则改造config加入 属性2还是6. :::2的defaultIndex,不需要加入index范围。 6,则不设置defaultIndex,加入index范围。所有函数做此改造。
//前提:都是指定的palas。不能再有其他的。 可再扩展,其他的可以覆盖属性名。
//在config类中添加属性 代表2,还是6. 抽象所有方法接口,作为封装。 方法内部自动根据2、6转向。
//配置类和链接类再区分。可以不区分。使用泛型吗?是不是还没这个必要。
//等用完了,把包括类、2类去掉,直接指向6即可。
//根据ID删除 但是由于以后delete的都是6.0.而2.0没有用到delete,所以可以测试deletebyquery即可。
[TestClass]
public class ES6
{
ElasticClient client = new ElasticClient(ESClientConfigureManager.ConnectSetting);
[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";
for (int i3 = 0; i3 < 1000; i3++)
{
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();
}
[TestMethod]
public void IndexOnly()
{
}
[TestMethod]
public void IndexOnlyDetail()
{
}
[TestMethod]
public void IndexOrUpdate()
{
}
[TestMethod]
public void ReverseNullValueForQuery()
{
}
[TestMethod]
public void Search()
{
//动态index测试
//var node = new Uri("http://minder:9200");
//var settings = new ConnectionSettings(node);
//var client = new ElasticClient(settings);
//内部调用 SearchDetail
}
[TestMethod]
public void SearchAllESInternalIDs()
{
}
public ISearchResponse<T> SearchDetail<T>(SearchDescriptor<T> searchQuery) where T : class
{
ISearchResponse<T> response = null;
try
{
response = client.Search<T>(searchQuery);
}
catch (Exception e)
{
}
return response;
}
[TestMethod]
public void SearchDetail()
{
//几种查询覆盖
//现有的took、hits、total、计数 (测试通过)
//返回多少条(测试通过)
//ID--字符串匹配(term\bool :must)(测试通过)
//match \multi_match分词匹配搜索(测试通过)
//order BY排序
//取反must_not、AND OR (测试通过)
//模糊查询QueryString (测试通过)
//时间范围 (测试通过)
//source (指定字段)(测试通过)
//delete-- (报错)
//聚合aggs--(测试通过)
//Delete--(测试通过)
try
{
#region 查询全部
//
// for (int i3 = 0; i3 < 1000; i3++)
// {
// Nest.SearchDescriptor<HTCommon.Data6.Item> builder2 = new Nest.SearchDescriptor<HTCommon.Data6.Item>()
// .Query(q => q.MatchAll()).Index((IndexName)("test_version2"));
// Nest.ISearchResponse<HTCommon.Data6.Item> rep2 = this.SearchDetail<HTCommon.Data6.Item>(builder2);
// Nest.SearchDescriptor<HTCommon.Data6.Item> builder6 = new Nest.SearchDescriptor<HTCommon.Data6.Item>()
//.Query(q => q.MatchAll()).Index((IndexName)("test_version6"));
// Nest.ISearchResponse<HTCommon.Data6.Item> rep6 = this.SearchDetail<HTCommon.Data6.Item>(builder6);
// if (i3 == 99)
// {
// }
// }
//
#endregion
#region 查询头部
// for (int i3 = 0; i3 < 1000; i3++)
// {
// Nest.SearchDescriptor<HTCommon.Data6.Item> builder2 = new Nest.SearchDescriptor<HTCommon.Data6.Item>()
// .Query(q => q.MatchAll()).From(0).Size(0).Index((IndexName)("test_version2"));
// Nest.ISearchResponse<HTCommon.Data6.Item> rep2 = this.SearchDetail<HTCommon.Data6.Item>(builder2);
// Nest.SearchDescriptor<HTCommon.Data6.Item> builder6 = new Nest.SearchDescriptor<HTCommon.Data6.Item>()
//.Query(q => q.MatchAll()).From(0).Size(0).Index((IndexName)("test_version6"));
// Nest.ISearchResponse<HTCommon.Data6.Item> rep6 = this.SearchDetail<HTCommon.Data6.Item>(builder6);
// if (i3 == 99)
// {
// }
// }
#endregion
#region 返回3
//见上面
#endregion
#region 查询term(term\bool :must)
// for (int i3 = 0; i3 < 1000; i3++)
// {
// Nest.SearchDescriptor<HTCommon.Data6.Item> builder2 = new Nest.SearchDescriptor<HTCommon.Data6.Item>()
// .Query(q => q.Bool(b => b.Must(
// m => m.Term(t => t.Field(tf => tf.ItemID).Value("test53"))
// ))).Index((IndexName)("test_version2")); ;
// Nest.ISearchResponse<HTCommon.Data6.Item> rep2 = this.SearchDetail<HTCommon.Data6.Item>(builder2);
// Nest.SearchDescriptor<HTCommon.Data6.Item> builder6 = new Nest.SearchDescriptor<HTCommon.Data6.Item>()
//.Query(q => q.Bool(b => b.Must(
// m => m.Term(t => t.Field(tf => tf.ItemID).Value("test54"))
// ))).Index((IndexName)("test_version6")); ;
// Nest.ISearchResponse<HTCommon.Data6.Item> rep6 = this.SearchDetail<HTCommon.Data6.Item>(builder6);
// if (i3 == 99)
// {
// }
// }
// Console.WriteLine("测试完毕");
#endregion
#region 查询term非主键 match \multi_match分词匹配搜索
// for (int i3 = 0; i3 < 1000; i3++)
// {
// Nest.SearchDescriptor<HTCommon.Data6.Item> builder2 = new Nest.SearchDescriptor<HTCommon.Data6.Item>()
// .Query(q => q.Bool(b => b.Must(
// m => m.MultiMatch(f => f.Fields(t => t.Field(tf => (tf.CrawlID))).Query("MA_Test_Oracle_Beige_NEWS"))
// ))).Index((IndexName)("test_version2"));
// Nest.ISearchResponse<HTCommon.Data6.Item> rep2 = this.SearchDetail<HTCommon.Data6.Item>(builder2);
// Nest.SearchDescriptor<HTCommon.Data6.Item> builder6 = new Nest.SearchDescriptor<HTCommon.Data6.Item>()
//.Query(q => q.Bool(b => b.Must(
// m => m.MultiMatch(f => f.Fields(t => t.Field(tf => (tf.CrawlID))).Query("MA_Test_Oracle_Beige_NEWS1"))
// ).Must(
// m => m.Term(t => t.Field(tf => tf.ItemID).Value("test54"))
// )
// )).Index((IndexName)("test_version6")); ;
// Nest.ISearchResponse<HTCommon.Data6.Item> rep6 = this.SearchDetail<HTCommon.Data6.Item>(builder6);
// if (i3 == 99)
// {
// }
// }
// Console.WriteLine("测试完毕");
//Console.WriteLine("测试完毕");
#endregion
#region order BY排序 (主键排序)
// Nest.SearchDescriptor<HTCommon.Data6.Item> builder2 = new Nest.SearchDescriptor<HTCommon.Data6.Item>()
//.Query(q => q.Bool(b => b.Must(
// m => m.Term(t => t.Field(tf => tf.ItemID).Value("test53"))
// ))).Sort(st => st.Ascending(asc => asc.ItemID)).Index((IndexName)("test_version")); ;
// //排序;
// Nest.ISearchResponse<HTCommon.Data6.Item> rep2 = this.SearchDetail<HTCommon.Data6.Item>(builder2);
#endregion
#region order BY排序 (时间排序)
// for (int i3 = 0; i3 < 1000; i3++)
// {
// Nest.SearchDescriptor<HTCommon.Data6.Item> builder2 = new Nest.SearchDescriptor<HTCommon.Data6.Item>()
// .Query(q => q.Bool(b => b.Must(
// m => m.MultiMatch(f => f.Fields(t => t.Field(tf => (tf.CrawlID))).Query("MA_Test_Oracle_Beige_NEWS"))
// ))).Sort(st => st.Ascending(asc => asc.FetchTime)).Index((IndexName)("test_version2"));
// //排序;
// Nest.ISearchResponse<HTCommon.Data6.Item> rep2 = this.SearchDetail<HTCommon.Data6.Item>(builder2);
// Nest.SearchDescriptor<HTCommon.Data6.Item> builder6 = new Nest.SearchDescriptor<HTCommon.Data6.Item>()
//.Query(q => q.Bool(b => b.Must(
// m => m.MultiMatch(f => f.Fields(t => t.Field(tf => (tf.CrawlID))).Query("MA_Test_Oracle_Beige_NEWS"))
// ))).Sort(st => st.Ascending(asc => asc.FetchTime)).Index((IndexName)("test_version6"));
// Nest.ISearchResponse<HTCommon.Data6.Item> rep6 = this.SearchDetail<HTCommon.Data6.Item>(builder6);
// if (i3 == 99)
// {
// }
// }
// Console.WriteLine("测试完毕");
#endregion
#region order BY排序 (时间排序) 非主键字段搜索
// for (int i3 = 0; i3 < 1000; i3++)
// {
// Nest.SearchDescriptor<HTCommon.Data6.Item> builder2 = new Nest.SearchDescriptor<HTCommon.Data6.Item>()
// .Query(q => q.Bool(b => b.Must(
// m => m.Term(t => t.Field(tf => tf.ItemID).Value("test53"))
// ))).Sort(st => st.Ascending(asc => asc.FetchTime)).Index((IndexName)("test_version2"));
// //排序;
// Nest.ISearchResponse<HTCommon.Data6.Item> rep2 = this.SearchDetail<HTCommon.Data6.Item>(builder2);
// Nest.SearchDescriptor<HTCommon.Data6.Item> builder6 = new Nest.SearchDescriptor<HTCommon.Data6.Item>()
//.Query(q => q.Bool(b => b.Must(
// m => m.Term(t => t.Field(tf => tf.ItemID).Value("test54"))
// ))).Sort(st => st.Ascending(asc => asc.FetchTime)).Index((IndexName)("test_version6"));
// Nest.ISearchResponse<HTCommon.Data6.Item> rep6 = this.SearchDetail<HTCommon.Data6.Item>(builder6);
// Nest.SearchDescriptor<HTCommon.Data6.Item> builder21 = new Nest.SearchDescriptor<HTCommon.Data6.Item>()
// .Query(q => q.Bool(b => b.Must(
// m => m.Term(t => t.Field(tf => tf.ItemID).Value("test54"))
// ))).Sort(st => st.Ascending(asc => asc.FetchTime)).Index((IndexName)("test_version2"));
// //排序;
// Nest.ISearchResponse<HTCommon.Data6.Item> rep21 = this.SearchDetail<HTCommon.Data6.Item>(builder21);
// if (i3 == 99)
// {
// }
// }
// Console.WriteLine("测试完毕");
// Console.WriteLine("测试完毕");
#endregion
#region 取反must_not
//要注意,mustnot 的hit 也是击中,代表去除了这1个。
// for (int i3 = 0; i3 < 1000; i3++)
// {
// Nest.SearchDescriptor<HTCommon.Data6.Item> builder2 = new Nest.SearchDescriptor<HTCommon.Data6.Item>()
// .Query(q => q.Bool(b => b.MustNot(mn => mn.Match(nm => nm.Field(f => f.ItemID).Query("test53"))))).Index((IndexName)("test_version2")); ;
// Nest.ISearchResponse<HTCommon.Data6.Item> rep2 = this.SearchDetail<HTCommon.Data6.Item>(builder2);
// Nest.SearchDescriptor<HTCommon.Data6.Item> builder21 = new Nest.SearchDescriptor<HTCommon.Data6.Item>()
// .Query(q => q.Bool(b => b.MustNot(mn => mn.Match(nm => nm.Field(f => f.ItemID).Query("test54"))))).Index((IndexName)("test_version6"));
// //排序;
// Nest.ISearchResponse<HTCommon.Data6.Item> rep21 = this.SearchDetail<HTCommon.Data6.Item>(builder21);
// if (i3 == 99)
// {
// }
//}
//Console.WriteLine("测试完毕");
#endregion
#region 模糊查询QueryString
// for (int i3 = 0; i3 < 1000; i3++)
// {
// Nest.SearchDescriptor<HTCommon.Data6.Item> builder2 = new Nest.SearchDescriptor<HTCommon.Data6.Item>()
// .Query(q => q.Bool(b => b.Must(
// m => m.QueryString(t => t.DefaultField(td => td.CrawlID).Query("M*"))
// ))).Index((IndexName)("test_version2"));;
// Nest.ISearchResponse<HTCommon.Data6.Item> rep2 = this.SearchDetail<HTCommon.Data6.Item>(builder2);
// Nest.SearchDescriptor<HTCommon.Data6.Item> builder21 = new Nest.SearchDescriptor<HTCommon.Data6.Item>()
// .Query(q => q.Bool(b => b.Must(
// m => m.QueryString(t => t.DefaultField(td => td.CrawlID).Query("M*"))))).Index((IndexName)("test_version6"));
// //排序;
// Nest.ISearchResponse<HTCommon.Data6.Item> rep21 = this.SearchDetail<HTCommon.Data6.Item>(builder21);
// if (i3 == 99)
// {
// }
//}
// Console.WriteLine("测试完毕");
#endregion
#region 时间范围
// for (int i3 = 0; i3 < 1000; i3++)
// {
//DateTime beginTime = DateTime.Parse("2018-06-06");
//DateTime endTime = DateTime.Parse("2018-06-18");
// Nest.SearchDescriptor<HTCommon.Data6.Item> builder212 = new Nest.SearchDescriptor<HTCommon.Data6.Item>()
//.Query(q => q.Bool(b => b.Must(
// m => m.Term(t => t.Field(tf => tf.ItemID).Value("test55")),
// m2 => m2.DateRange
// (r =>
// r.Field(f => f.FetchTime)
// .GreaterThanOrEquals(beginTime)
// .LessThanOrEquals(endTime)
// .TimeZone("+08:00")
// )
// )
// ));
// Nest.ISearchResponse<HTCommon.Data6.Item> rep212 = this.SearchDetail<HTCommon.Data6.Item>(builder212);
// Nest.SearchDescriptor<HTCommon.Data6.Item> builder2 = new Nest.SearchDescriptor<HTCommon.Data6.Item>()
//.Query(q => q.Bool(b => b.Must(
// m => m.Term(t => t.Field(tf => tf.ItemID).Value("test54")),
// m2 => m2.DateRange
// (r =>
// r.Field(f => f.FetchTime)
// .GreaterThanOrEquals(beginTime)
// .LessThanOrEquals(endTime)
// .TimeZone("+08:00")
// )
// )
// )).Index((IndexName)("test_version2"));
// Nest.ISearchResponse<HTCommon.Data6.Item> rep2 = this.SearchDetail<HTCommon.Data6.Item>(builder2);
// Nest.SearchDescriptor<HTCommon.Data6.Item> builder21 = new Nest.SearchDescriptor<HTCommon.Data6.Item>()
//.Query(q => q.Bool(b => b.Must(
// m => m.Term(t => t.Field(tf => tf.ItemID).Value("test53")),
// m2 => m2.DateRange
// (r =>
// r.Field(f => f.FetchTime)
// .GreaterThanOrEquals(beginTime)
// .LessThanOrEquals(endTime)
// .TimeZone("+08:00")
// )
// )
// )).Index((IndexName)("test_version6"));
// Nest.ISearchResponse<HTCommon.Data6.Item> rep21 = this.SearchDetail<HTCommon.Data6.Item>(builder21);
// if (i3 == 99)
// {
// }
//}
////Console.WriteLine("测试完毕");
#endregion
#region source (指定字段)
// for (int i3 = 0; i3 < 1000; i3++)
// {
// //6-6
// Nest.SearchDescriptor<HTCommon.Data6.Item> builder2 = new Nest.SearchDescriptor<HTCommon.Data6.Item>()
//.Query(q => q.Bool(b => b.Must(
// m => m.Term(t => t.Field(tf => tf.ItemID).Value("test53"))
// )))
// .Source(s => s.Includes(si => si.Fields(fd => fd.CrawlID, fd => fd.FetchTime))).Index((IndexName)("test_version2"));
// ;
// Nest.ISearchResponse<HTCommon.Data6.Item> rep2 = this.SearchDetail<HTCommon.Data6.Item>(builder2);
// Nest.SearchDescriptor<HTCommon.Data6.Item> builder21 = new Nest.SearchDescriptor<HTCommon.Data6.Item>()
// .Query(q => q.Bool(b => b.MustNot(mn => mn.Match(nm => nm.Field(f => f.ItemID).Query("test54"))))).
// Source(s => s.Includes(si => si.Fields(fd => fd.CrawlID, fd => fd.FetchTime))).Index((IndexName)("test_version6"));
// Nest.ISearchResponse<HTCommon.Data6.Item> rep21 = this.SearchDetail<HTCommon.Data6.Item>(builder21);
// if (i3 == 99)
// {
// }
// }
// Console.WriteLine("测试完毕");
#endregion
#region DeleteByQuery
Nest.QueryContainer qc6 = new Nest.QueryContainer(
new Nest.TermQuery
{
Field = "itemID.keyword",
Value = "test22"
}
);
var delete6 = new Nest.DeleteByQueryRequest<object>("test_version6", "items");
delete6.Query = qc6;
Nest.ElasticClient client6 = new Nest.ElasticClient(TestTwoES2_6.ES6_1_0.ESClientConfigureManager.ConnectSetting);
var result6 = client6.DeleteByQuery(delete6);
#endregion
#region Delete
//这是根据ID删除
//Nest.DocumentPath<HTCommon.Data6.Item> deletePath6 = new Nest.DocumentPath<HTCommon.Data6.Item>("test53");
//var result6 = client.Delete(deletePath6, s => s.Index("test_version6"));
//IDeleteRequest request = new DeleteRequest("test_version6", typeof(HTCommon.Data6.Item), "test53");
//var result6 = client.Delete(request);
//但是由于以后delete的都是6.0.而2.0没有用到delete,所以可以测试deletebyquery即可。
//Nest.DocumentPath<HTCommon.Data6.Item> deletePath6 = new Nest.DocumentPath<HTCommon.Data6.Item>("test53");
//var result6 = client.Delete(deletePath6, s => s.Index("test_version6"));
#endregion
Console.WriteLine("测试完毕");
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
Console.ReadLine();
}
[TestMethod]
public void SearchESInternalID()
{
}
[TestMethod]
public void SearchTop()
{
}
[TestMethod]
public void Serialize()
{
}
[TestMethod]
public void TestMethod1()
public void StopMaintainThread()
{
}
}
}
using Elasticsearch.Net;
using Elasticsearch.Net;
using Nest;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Text.RegularExpressions;
namespace UnitTestProject.TestES
{
public sealed class ESClientConfigureManager
{
public static List<Uri> Uris { get; private set; }
/// <summary>
/// ES连接设置
/// </summary>
public static ConnectionSettings ConnectSetting { get; private set; }
private const String ConnectionStringIndex = "6MinderESDatabase";
private const String HostIndex = "host";
private const String PortIndex = "port";
private const String DefaultIndexIndex = "defaultIndex";
static ESClientConfigureManager()
{
String connectionString = ConfigurationManager.ConnectionStrings[ConnectionStringIndex].ConnectionString;
String[] namedValues = connectionString.Split(';');
Dictionary<String, String> nvPair = new Dictionary<String, String>();
foreach (String nv in namedValues)
{
String[] pair = nv.Split('=');
nvPair[pair[0]] = pair[1];
}
String _url = GetValueByName(nvPair, HostIndex, "tank.palaspom.com|mech.palaspom.com");
String _port = GetValueByName(nvPair, PortIndex, "19235");
//支持多Uri模式,要求多个链接使用 | 分隔,在分隔后数量相同的情况下按照顺序一一对应,如果其中一方仅有一个则使用它对应对方所有部分
string[] urls = _url.Split('|');
string[] ports = _port.Split('|');
if (urls == null || ports == null || urls.Length < 1 || ports.Length < 1)
throw new Exception("Unable get the elasticsearch config pool setting.");
Uris = new List<Uri>();
if (urls.Length == ports.Length)
{
for (int i = 0; i < urls.Length; i++)
{
String formattedUrl = Regex.IsMatch(urls[i], @"://") ? urls[i] : String.Format("http://{0}", urls[i]);
Uris.Add(new Uri(String.Format("{0}:{1}", formattedUrl, ports[i])));
}
}
else if (urls.Length > 1 && ports.Length == 1)
{
for (int i = 0; i < urls.Length; i++)
{
String formattedUrl = Regex.IsMatch(urls[i], @"://") ? urls[i] : String.Format("http://{0}", urls[i]);
Uris.Add(new Uri(String.Format("{0}:{1}", formattedUrl, ports[0])));
}
}
else if (urls.Length == 1 && ports.Length > 1)
{
String formattedUrl = Regex.IsMatch(urls[0], @"://") ? urls[0] : String.Format("http://{0}", urls[0]);
for (int i = 0; i < ports.Length; i++)
{
Uris.Add(new Uri(String.Format("{0}:{1}", formattedUrl, ports[i])));
}
}
else
{
throw new Exception("The elasticsearch config pool setting is error.");
}
var pool = new StaticConnectionPool(Uris);
ConnectSetting = new ConnectionSettings(pool).DisableDirectStreaming();
//ConnectSetting = new ConnectionSettings(pool).DefaultIndex("test_version6").DisableDirectStreaming().EnableHttpCompression();
}
private static String GetValueByName(Dictionary<String, String> nvPair, String name, String defaultValue)
{
String value = null;
if (nvPair.TryGetValue(name, out value))
{
return value;
}
return defaultValue;
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
......@@ -59,6 +59,7 @@
<HintPath>..\packages\Newtonsoft.Json.11.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Configuration.Install" />
</ItemGroup>
<Choose>
......@@ -89,6 +90,7 @@
<Compile Include="TestES\TestES2\ESAccess.cs" />
<Compile Include="TestES\TestES2\ESItemAccess.cs" />
<Compile Include="TestES\TestES6\ES6.cs" />
<Compile Include="TestES\TestES6\ESClientConfigureManager.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config">
......
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
......@@ -7,8 +7,14 @@
<connectionStrings>
<add name="ESDatabase" connectionString="host=test_version;port=9200;defaultIndex=test_version6;requesttimeout=30000;provider=2" />
<!--<add name="ESDatabase" connectionString="host=test_version;port=9200;defaultIndex=test_version6;requesttimeout=30000" providerName="6" />
<add name="6MinderESDatabase" connectionString="host=test_version;port=9200;defaultIndex=test_version6;requesttimeout=30000" />
<add name="2localESDatabase" connectionString="host=localhost;port=9200;defaultIndex=test_version2;requesttimeout=30000" />
<add name="2localESDatabase" connectionString="host=localhost;port=9200;defaultIndex=test_version2;requesttimeout=30000" />-->
</connectionStrings>
......
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
......@@ -7,17 +7,17 @@
<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="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" />-->
......
52e149e9cc4fec00eefaac2a0d3e5fac38b5cd04
95629e2ac04e9d3473c98b5aefb86d1c73a79a7e
52e149e9cc4fec00eefaac2a0d3e5fac38b5cd04
95629e2ac04e9d3473c98b5aefb86d1c73a79a7e
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