0
推文在一個索引可以有這樣的(不嚴格JSON的結構,只是想傳達的結構:)我可以將POCO綁定到Elasticsearch命中以獲得更強的輸入嗎?
{
text: string
created_at: DateTime
mention: [
{
name: string
screen_name: string
start: int
end: int
}
],
hashtag: [
// multiple string/int props similar to mention
],
link: [
// multiple string/int props similar to mention
],
user: {
name: string
screen_name: string
profile_image_url: string
}
}
使用NEST客戶端時,我得到預期的命中率,但我下的印象我可以映射POCO的結果來獲得更強的類型,例如
public class TweetDocument
{
public string text { get; set; }
public DateTime created_at { get; set; }
public List<Mention> mention { get; set; }
public List<Hashtag> hashtag { get; set; }
public List<Link> link { get; set; }
public User user { get; set; }
}
public class Mention
{
public string name { get; set; }
public string screen_name { get; set; }
public int start { get; set; }
public int end { get; set; }
}
// ... other POCO's for Hashtag, Link and User
字符串屬性text
和DateTime財產created_at
綁定好了,但mention
,hashtag
和link
性質均爲空,當我在響應的命中例如看
var response = client.Search<TweetDocument>(q);
var firstHit = response.Hits.Hits.FirstOrDefault();
// firstHit.Fields.hashtag, .mention, .link and .user are all null
我已經看到了一些屬性,但還沒有真正想出如何使用它們,例如, ElasticProperty
和ElasticType
。 如何從我的索引中填充這些集合,包括非集合.User子屬性?
我指定了不正確的字段,例如查詢中的「提及。名稱」而不是「提及」。我還需要用ElasticType(Name =「whatever」)]來裝飾POCO,但我確實得到了它的工作。 –
你可以在ConnectionSettings上使用'.SetPropertyNameInferrer(p => p.ToPythonCase())'來全局指定屬性名稱的外觀。默認情況下爲NEST camelCase的屬性名稱。這有助於防止需要在任何地方抹灰。 –