我正在开发iOS和Android应用程序与Xamarin 6.1 Xamarin.Forms NEST和我使用Xamarin.Forms 2.3.1 该应用程序的Guid ID比较扫描QR使用ZXing.Net.Mobile.Forms 2.1.4包含Guid Id并将其保存为一个字符串到我的ElasticSearch中。要使用ElasticSearch进行连接我正在使用NEST 2.x使用不工作
问题是,当我再次扫描相同的QR(当我确定它已经被索引时),它被检测为新值,甚至是值是一样的(都比较字符串)。但是,我试图删除破折号( - )从存储或比较它们之前,它的工作原理。
这是我的模型:
public class Box
{
[String(Analyzer = "null")]
public string id { get; set; }
public string lastUpdate { get; set; }
}
result.Text就是我从QR让我知道肯定是一个字符串,这是我怎么索引呢:
scannedQR = result.Text;
// INDEXING
var timeStamp = GetTimestamp(DateTime.Now);
var customBox = new Box {
id= scannedQR,
lastUpdate = timeStamp
};
var res = client.Index(customBox, p => p
.Index("airstorage")
.Type("boxes")
.Id(scannedQR)
.Refresh()
);
这就是我如何检查是否QR已存在:
var resSearch = client.Search<Box>(s => s
.Index("airstorage")
.Type("boxes")
.From(0)
.Size(10)
.Query(q => q
.Term(p => p.id, scannedQR)
)
);
if (resSearch.Documents.Count() > 0) {
Console.WriteLine("EXISTING");
}
else {
Console.WriteLine("NEW BOX");
}
我还尝试将该属性设置为.NotAnalyse创建时的ElasticSearch索引,如here中所示,但仍然无效。
任何任何想法?一切都欢迎!
谢谢!
感谢@RussCam!我将POCO添加到'id'声明和'.OpType(OpType.Create)',现在它工作了! – svicente3
你能帮我一下吗? ^^'http://stackoverflow.com/questions/39931708/how-to-store-a-c-sharp-list-of-objects-into-elasticsearch-with-nest-2-x/39932064#39932064 – svicente3