我正在尝试使用Spring Data Elasticsearch在一些Elasticsearch索引中存储推文(对于推文请求,我使用的是twitter4j)。
我已经遵循了一些基本的例子,我正在使用这个基本的带注释的POJO(已经删除了复杂类型的元数据):
void Copy(double **mt, int sx, int ex, int sy, int ey, double **res)
{
int i;
int t = sizeof(double)*(ey-sy+1);
for(i = 0; i < ex-sx+1; i++)
memcpy(&mt[i][0],&res[sx+i][sy], t);
return;
}
要使用此模型存储推文,我使用:
Sub ViewInternetHeader()
Dim olItem As Outlook.MailItem, olMsg As Outlook.MailItem
For Each olItem In Application.ActiveExplorer.Selection
Set olMsg = Application.CreateItem(olMailItem)
olMsg.BodyFormat = olFormatPlain
olMsg.Body = ""
olMsg.Body = olItem.To & Chr(13) & olItem.Sender
olMsg.Display
Next
Set olMsg = Nothing
End Sub
并在我的存储服务中:
@Document(indexName = "twitter", type = "tweet")
public class StorableTweet {
@Id
private long id;
private String createdAt;
private String text;
private String source;
private boolean isTruncated;
private long inReplyToStatusId;
private long inReplyToUserId;
private boolean isFavorited;
private boolean isRetweeted;
private int favoriteCount;
private String inReplyToScreenName;
private String userScreenName = null;
// Getters/setters removed
}
它工作正常,但我的推文ID存储在“_id”(为什么不存在),而其他一些来自无处的号码存储在“id”中(为什么......?):
public interface TweetRepository extends ElasticsearchRepository<StorableTweet, Long> {
}
我想要的是我的推文ID存储在“_id”(并且没有“id”字段),我的推文ID存储在“id”中,并且在“_id”中生成了数字,并且摆脱了这个“id”中随机无用的数字。
修改
映射:
tweetRepository.save(storableTweet);
编辑2:看起来问题不是关于@Id注释而是关于“长”类型。当通过Spring Data Elasticsearch存储到elasticsearch中时,其他一些longs(不是全部)被转换(或多或少几个单位)。