Commit 67416fd4 by mahaisong

fix:测试去掉属性path,直接使用nest, 通过

parent 689160bb
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
<!--必选:20187150点迁移完成前保留--> <!--必选:20187150点迁移完成前保留-->
<add name="2ESDatabase" connectionString="host=127.0.0.1|localhost;port=9200;defaultindex=test;requesttimeout=0:1:00;version=2;" /> <add name="2ESDatabase" connectionString="host=127.0.0.1|localhost;port=9200;defaultindex=palas;requesttimeout=0:1:00;version=2;" />
<!--必选:(全部小写)6没有defaultindexIndex:palas前缀字符+“_”+type)--> <!--必选:(全部小写)6没有defaultindexIndex:palas前缀字符+“_”+type)-->
......
using Nest2_5_8; using Nest;
using Nest2_5_8; using Nest;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
...@@ -7,68 +7,34 @@ using System.Threading.Tasks; ...@@ -7,68 +7,34 @@ using System.Threading.Tasks;
namespace UnitTestProject namespace UnitTestProject
{ {
/// <summary>
/// 反馈信息
/// </summary>
[ElasticsearchType(Name = "feedbacks")]
public class FeedbackModel
{
/// <summary>
/// 用户编号
/// </summary>
public string UserId { set; get; }
/// <summary>
/// 反馈内容
/// </summary>
public string Content { set; get; }
/// <summary>
/// 创建时间
/// </summary>
public long CreateTime { set; get; }
/// <summary>
/// 反馈编号
/// </summary>
public string FeedbackID { set; get; }
/// <summary>
/// 反馈包含图片
/// </summary>
public List<string> Images { set; get; }
/// <summary>
/// 反馈的回复,为了降低复杂度,回复暂时没有层级关系,按照时间排序
/// </summary>
[Nested(CopyTo = "replys")]
public List<FeedbackModel> Replys { set; get; }
}
[ElasticsearchType(Name = "boolwriting")]
//[ElasticsearchType(Name = "boolwriting")] public class BoolWriting
//public class BoolWriting {
//{ public string BoolPushID { get; set; }
// public string BoolPushID { get; set; } public string AbilityName { get; set; }
// public string AbilityName { get; set; } [Text(Name = "stockName")]
// [Text(Name = "stockName")] public string Name { get; set; }
// public string Name { get; set; } [Number(Name = "pubDateTimeStamp")]
// [Number(Name = "pubDateTimeStamp")] public long PubDate { get; set; }
// public long PubDate { get; set; } [Text(Name = "tendency1")]
// [Text(Name = "tendency1")] public string Tendency { get; set; }
// public string Tendency { get; set; } [Text(Name = "typename")]
// [Text(Name = "typename")] public string Type { get; set; }
// public string Type { get; set; } public string FinancialName { get; set; }
// public string FinancialName { get; set; } [Text(Name = "status1")]
// [Text(Name = "status1")] public string Status { get; set; }
// public string Status { get; set; } [Text(Name = "ability1")]
// [Text(Name = "ability1")] public string Ability { get; set; }
// public string Ability { get; set; } [Text(Name = "codeNum")]
// [Text(Name = "codeNum")] public string Code { get; set; }
// public string Code { get; set; } [Text(Name = "pushContent")]
// [Text(Name = "pushContent")] public string Content { get; set; }
// public string Content { get; set; } [Text(Name = "value1")]
// [Text(Name = "value1")] public double Value { get; set; }
// public double Value { get; set; } public int Pushing { get; set; }
// public int Pushing { get; set; } }
//}
} }
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Nest2_5_8;
namespace TestUnit
{
/// <summary>
/// 反馈信息
/// </summary>
[ElasticsearchType(Name = "feedbacks")]
public class FeedbackModel2
{
/// <summary>
/// 用户编号
/// </summary>
public string UserId { set; get; }
/// <summary>
/// 反馈内容
/// </summary>
public string Content { set; get; }
/// <summary>
/// 创建时间
/// </summary>
public long CreateTime { set; get; }
/// <summary>
/// 反馈编号
/// </summary>
public string FeedbackID { set; get; }
/// <summary>
/// 反馈包含图片
/// </summary>
public List<string> Images { set; get; }
/// <summary>
/// 反馈的回复,为了降低复杂度,回复暂时没有层级关系,按照时间排序
/// </summary>
[Nested/*(CopyTo = "replys")*/]
public List<FeedbackModel2> Replys { set; get; }
}
}
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Nest;
namespace TestUnit
{
/// <summary>
/// 反馈信息
/// </summary>
[ElasticsearchType(Name = "testfeedbacks")]
public class TestFeedbackModel6
{
/// <summary>
/// 用户编号
/// </summary>
public string TestUserId { set; get; }
/// <summary>
/// 反馈内容
/// </summary>
public string TestContent { set; get; }
/// <summary>
/// 创建时间
/// </summary>
public long TestCreateTime { set; get; }
/// <summary>
/// 反馈编号
/// </summary>
public string TestFeedbackID { set; get; }
/// <summary>
/// 反馈包含图片
/// </summary>
public List<string> TestImages { set; get; }
/// <summary>
/// 反馈的回复,为了降低复杂度,回复暂时没有层级关系,按照时间排序
/// </summary>
[Nested]
public List<TestFeedbackModel6> TestReplys { set; get; }
}
}
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
...@@ -66,7 +66,11 @@ ...@@ -66,7 +66,11 @@
<Compile Include="Author.cs" /> <Compile Include="Author.cs" />
<Compile Include="BoolWriting.cs" /> <Compile Include="BoolWriting.cs" />
<Compile Include="ES6.cs" /> <Compile Include="ES6.cs" />
<Compile Include="FeedbackModel6.cs" />
<Compile Include="FeedbackModel2.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UnitTest_FeedbackModel6.cs" />
<Compile Include="UnitTest_FeedbackModel2.cs" />
<Compile Include="UnitTestES6-2.cs" /> <Compile Include="UnitTestES6-2.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
......
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using HTCommon.Helper;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Nest;
using TestES6_2.ES2;
namespace TestUnit
{
[TestClass]
public class UnitTest_FeedbackModel2
{
[TestMethod]
public void TestMethodFeedbackModel2()
{
/// <summary>
/// [Finish] 反馈建议,暂时不支持图片,并且使用get方法,需要优化
/// </summary>
/// <param name="userID">用户ID</param>
/// <param name="content">反馈内容</param>
/// <param name="imageUrls">图片的Url,多个使用 ',' 分隔</param>
/// <param name="parentFeedbackID">反馈的父ID,用于回复反馈</param>
/// <returns>是否反馈成功</returns>
string userID = "test4";
string content = "test4";
string imageUrls = null;
string parentFeedbackID = "f4b2fb4cfd25200971f8c4a8481f3577";
FeedbackModel2 feedback = new FeedbackModel2();
feedback.Content = content;
feedback.CreateTime = DateTimeUtility.GetUnixTimeStamp(DateTime.Now);
if (!String.IsNullOrWhiteSpace(imageUrls))
{
feedback.Images = imageUrls.Split(',').ToList();
}
feedback.UserId = userID;
feedback.FeedbackID = MD5Helper.getMd5Hash(userID + "/n" + content + imageUrls + parentFeedbackID);
ElasticClient client = new ElasticClient(TestES6_2.ESClientConfigureManager2.ConnectSetting);
//var result = client.Index<FeedbackModel>(feedback, f => f.Id(""));
//SearchDescriptor<FeedbackModel> builder = new SearchDescriptor<FeedbackModel>()
// .Query(q => q.Term(f => f.FeedbackID, parentFeedbackID));
SearchDescriptor<FeedbackModel2> builder = new SearchDescriptor<FeedbackModel2>()
.Take(1)
.Query(q => q.Term(f => f.FeedbackID, parentFeedbackID));
ISearchResponse<FeedbackModel2> response = null;
try
{
response = client.Search<FeedbackModel2>(builder);
}
catch (Exception e)
{
}
FeedbackModel2 parentFeedback = response.Documents.ToArray().FirstOrDefault();
if (parentFeedback != null)
{
if (parentFeedback.Replys == null)
parentFeedback.Replys = new List<FeedbackModel2>();
parentFeedback.Replys.Add(feedback);
var result1 = client.Index(parentFeedback, f => f.Id(parentFeedback.FeedbackID));
}
else
{
if (parentFeedback.Replys == null)
parentFeedback.Replys = new List<FeedbackModel2>();
parentFeedback.Replys.Add(feedback);
var result2 = client.Index(parentFeedback, f => f.Id(parentFeedback.FeedbackID));
}
var result3 = client.Index(feedback, f => f.Id(feedback.FeedbackID));
}
}
}
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using HTCommon.Helper;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Nest;
using TestES6_2;
namespace TestUnit
{
[TestClass]
public class UnitTest_FeedbackModel6
{
[TestMethod]
public void TestMethodFeedbackModel6()
{
/// <summary>
/// [Finish] 反馈建议,暂时不支持图片,并且使用get方法,需要优化
/// </summary>
/// <param name="userID">用户ID</param>
/// <param name="content">反馈内容</param>
/// <param name="imageUrls">图片的Url,多个使用 ',' 分隔</param>
/// <param name="parentFeedbackID">反馈的父ID,用于回复反馈</param>
/// <returns>是否反馈成功</returns>
string userID = "testTEST66666";
string content = "testTEST66666";
string imageUrls = null;
string parentFeedbackID = "556bc36b1b10009a9a2fba080ff99acd";
//string parentFeedbackID = "";
TestFeedbackModel6 feedback = new TestFeedbackModel6();
feedback.TestContent = content;
feedback.TestCreateTime = DateTimeUtility.GetUnixTimeStamp(DateTime.Now);
if (!String.IsNullOrWhiteSpace(imageUrls))
{
feedback.TestImages = imageUrls.Split(',').ToList();
}
feedback.TestUserId = userID;
feedback.TestFeedbackID = MD5Helper.getMd5Hash(userID + "/n" + content + imageUrls + parentFeedbackID);
//var t= ESAccess.Index<TestFeedbackModel6>(feedback);
SearchDescriptor<TestFeedbackModel6> builder = new SearchDescriptor<TestFeedbackModel6>()
.Take(1)
.Query(q => q.Term(f => f.TestFeedbackID, parentFeedbackID));
TestFeedbackModel6 parentFeedback = ESAccess.SearchTop<TestFeedbackModel6>(builder); ;
if (parentFeedback != null)
{
if (parentFeedback.TestReplys == null)
parentFeedback.TestReplys = new List<TestFeedbackModel6>();
parentFeedback.TestReplys.Add(feedback);
ESAccess.Index(parentFeedback, -1,parentFeedback.TestFeedbackID);
}
else
{
if (parentFeedback.TestReplys == null)
parentFeedback.TestReplys = new List<TestFeedbackModel6>();
parentFeedback.TestReplys.Add(feedback);
ESAccess.Index(parentFeedback, -1, parentFeedback.TestFeedbackID);
}
var result3 = ESAccess.Index(feedback, -1, feedback.TestFeedbackID);
}
}
}
This source diff could not be displayed because it is too large. You can view the blob instead.
[2018/6/14 11:04:42][][][TestES6-2.exe][TestES6_2.ES2.ESAccess][Index][@]ES Index Error:System.AggregateException: 发生一个或多个错误。 ---> System.ArgumentException: Index name is null for the given type and no default index is set. Map an index name using ConnectionSettings.DefaultMappingFor<TDocument>() or set a default index using ConnectionSettings.DefaultIndex().
[2018/6/14 11:04:42][][][TestES6-2.exe][TestES6_2.ES2.ESAccess][Index][@]ES Index Error:System.AggregateException: 发生一个或多个错误。 ---> System.ArgumentException: Index name is null for the given type and no default index is set. Map an index name using ConnectionSettings.DefaultMappingFor<TDocument>() or set a default index using ConnectionSettings.DefaultIndex().
在 Nest.IndexNameResolver.ValidateIndexName(String indexName)
在 Nest.IndexNameResolver.Resolve(Type type)
在 Nest.IndexNameResolver.Resolve(IndexName i)
在 Nest.IndexName.GetString(IConnectionConfigurationValues settings)
在 Nest.RouteValues.Resolve(IConnectionSettingsValues settings)
在 Nest.ElasticClient.<Nest-IHighLevelToLowLevelDispatcher-DispatchAsync>d__273`4.MoveNext()
--- 内部异常堆栈跟踪的结尾 ---
在 System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
在 System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
在 System.Threading.Tasks.Task`1.get_Result()
在 TestES6_2.ES2.ESAccess.Index[T](T value, Int64 version, String id) 位置 D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestES6-2\ES2\ESAccess.cs:行号 264
---> (内部异常 #0) System.ArgumentException: Index name is null for the given type and no default index is set. Map an index name using ConnectionSettings.DefaultMappingFor<TDocument>() or set a default index using ConnectionSettings.DefaultIndex().
在 Nest.IndexNameResolver.ValidateIndexName(String indexName)
在 Nest.IndexNameResolver.Resolve(Type type)
在 Nest.IndexNameResolver.Resolve(IndexName i)
在 Nest.IndexName.GetString(IConnectionConfigurationValues settings)
在 Nest.RouteValues.Resolve(IConnectionSettingsValues settings)
在 Nest.ElasticClient.<Nest-IHighLevelToLowLevelDispatcher-DispatchAsync>d__273`4.MoveNext()<---
,value:TestUnit.FeedbackModel,StackTrace: 在 System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
在 System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
在 System.Threading.Tasks.Task`1.get_Result()
在 TestES6_2.ES2.ESAccess.Index[T](T value, Int64 version, String id) 位置 D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestES6-2\ES2\ESAccess.cs:行号 264
[2018/6/14 11:48:54][][][TestES6-2.exe][TestES6_2.ES6.ESAccess][Index][@]ES Index Error:System.Exception: TestUnit.FeedbackModel类,没有设置ElasticsearchTypeAttribute标签,无法对应ES中index下的type
在 TestES6_2.ES6.ESAccess.From(Type type) 位置 D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestES6-2\ES6\ESAccess.cs:行号 690
在 TestES6_2.ES6.ESAccess.Index[T](T value, Int64 version, String id, String index) 位置 D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestES6-2\ES6\ESAccess.cs:行号 310,value:TestUnit.FeedbackModel,StackTrace: 在 TestES6_2.ES6.ESAccess.From(Type type) 位置 D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestES6-2\ES6\ESAccess.cs:行号 690
在 TestES6_2.ES6.ESAccess.Index[T](T value, Int64 version, String id, String index) 位置 D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestES6-2\ES6\ESAccess.cs:行号 310
This source diff could not be displayed because it is too large. You can view the blob instead.
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
<!--必选:20187150点迁移完成前保留--> <!--必选:20187150点迁移完成前保留-->
<add name="2ESDatabase" connectionString="host=127.0.0.1|localhost;port=9200;defaultindex=test;requesttimeout=0:1:00;version=2;" /> <add name="2ESDatabase" connectionString="host=127.0.0.1|localhost;port=9200;defaultindex=palas;requesttimeout=0:1:00;version=2;" />
<!--必选:(全部小写)6没有defaultindexIndex:palas前缀字符+“_”+type)--> <!--必选:(全部小写)6没有defaultindexIndex:palas前缀字符+“_”+type)-->
......
edbee5aaa8d2f637fb9b9c16b990e1ec2a89fc86 92fa3f8a6bbc055382d7c8e4a3b73b088cb13d08
edbee5aaa8d2f637fb9b9c16b990e1ec2a89fc86 92fa3f8a6bbc055382d7c8e4a3b73b088cb13d08
D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestUnit\bin\Debug\Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.dll D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestUnit\bin\Debug\Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.dll
...@@ -59,3 +59,7 @@ D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestUnit\bin\Debug\New ...@@ -59,3 +59,7 @@ D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestUnit\bin\Debug\New
D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestUnit\bin\Debug\HtmlAgilityPack.pdb D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestUnit\bin\Debug\HtmlAgilityPack.pdb
D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestUnit\bin\Debug\HtmlAgilityPack.xml D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestUnit\bin\Debug\HtmlAgilityPack.xml
D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestUnit\bin\Debug\NPOI.xml D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestUnit\bin\Debug\NPOI.xml
D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestUnit\bin\Debug\Elasticsearch.Net2_5_8.dll
D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestUnit\bin\Debug\Nest2_5_8.dll
D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestUnit\bin\Debug\Elasticsearch.Net2_5_8.xml
D:\smallproject\12.ES支持2-6多版本\TestUnit\TestUnit\TestUnit\bin\Debug\Nest2_5_8.xml
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