gpt4 book ai didi

ElasticSearch 和 Nest : Why am I missing the id field on a query?

转载 作者:行者123 更新时间:2023-11-29 02:51:05 26 4
gpt4 key购买 nike

我创建了一个代表 session 的简单对象,该对象具有时间、地点、名称、主题等元素,并通过 Nest 在 ElasticSearch 中对其进行了索引。它有一个我留空的 Id 字段,以便 ES 可以生成它们。

稍后我检索了所有缺少 GEO 坐标的文档,以便我可以更新它们。我返回的所有元素的 id 字段仍然为空,当我将它们更新回 ES 时,它会为它们创建新文档。

我在这里缺少什么使我所有的 id 都为空?

谢谢

这是 Meeting 类(id 属性是多余的,但我还是试过了)

[ElasticType(IdProperty = "Id")]
public class Meeting
{
public string Id { get; set; }
public string Code { get; set; }
public string Day { get; set; }
public string Town { get; set; }
public string Name { get; set; }
public string Location { get; set; }
public string OriginalTime { get; set; }
public string OriginalTimeCleaned { get; set; }
public string Handicap { get; set; }
public string FormattedAddress { get; set; }
public Coordinates Coordinates { get; set; }
public List<MeetingTime> Times = new List<MeetingTime>();
public bool IsProcessed { get; set; }
}

这是我检索 session 的方式

 public static List<Meeting> GetAddressesWithMissingCoordinates()
{

var result = Client.Search<Meeting>(s => s
.Index("meetings")
.AllTypes()
.Query(p => p.Filtered(f => f.Filter(x => x.Missing(c => c.Coordinates)))));


return result.Documents.ToList();
}

这是我的更新语句,Id为空

 public static void UpdateMeetingCoordinates(Meeting meeting, Coordinates coordinates)
{
meeting.Coordinates = coordinates;

var response = Client.Index(meeting, u => u
.Index("meetings")
.Type("meeting")
//.Id(meeting.Id.ToString())
.Refresh()
);

Console.WriteLine(response);
}

我也尝试过部分更新,但没有成功。

最佳答案

有一种获取内部 ID 的方法,如 this issue 中所述请求此功能。

与其使用 response.Documents,不如这样做:

var results = response.Hits.Select(hit =>
{
var result = hit.Source;
result.Id = hit.Id;
return result;
});

关于ElasticSearch 和 Nest : Why am I missing the id field on a query?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33834141/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com