这是获取firstname / lastname的查询......
public IEnumerable<ConnectionsModel> NewSearch(SearchQueryModel searchQuery)
{
var node = new Uri(Utilities.UrlConstants.SearchServiceUrl);
var setting = new ConnectionSettings(node);
var client = new ElasticClient(setting);
var results = client.Search<Persondb>(s => s
.From(0)
.Size(10)
.Query(q => q
.Bool(b => b
.Must(ms =>
ms.Match(mt0 => mt0.Field(f => f.FirstName).Query(searchQuery.FirstName)) &&
ms.Match(mt0 => mt0.Field(f => f.LastName).Query(searchQuery.LastName)) &&
ms.Match(mt0 => mt0.Field(f => f.CurrentCompany).Query(searchQuery.CurrentCompany)) &&
ms.Match(mt0 => mt0.Field(f => f.ProfileTitle).Query(searchQuery.ProfileTitle)) &&
ms.Match(mt0 => mt0.Field(f => f.IsNewUser).Query("false")) &&
))));
var queryList = results.Documents.ToList();
这是一个包含2个嵌套对象的示例数据。引用/经验
{
"_index": "persondb",
"_type": "userdata",
"_id": "5501eb7854355e3b8c879410",
"_score": 1,
"_source": {
"id": "5501eb7854355e3b8c879410",
"firstName": "Zada",
"lastName": "Teeters",
"currentCompany": "John Barns Inc",
"profileTitle": "software developer",
"currentlyLooking": true,
"isNewUser": false,
"references": [
{
"relatedTo": "5540fb080e32651300b02595",
"relationshipType": "colleage",
"id": "5540fbac0e32651300b0300d"
},
{
"relatedTo": "554100880e32651300b035d7",
"relationshipType": "family",
"id": "554100e90e32651300b03b30"
}
],
"experiences": [
{
"addrCity": "Stockton",
"addrCountry": "United States",
"addrState": "California",
"employer": "KPMG",
"id": "5501eb7a54355e3b8c8795c3",
"workType": "Internship",
"startDate": "2007-09-12T12:39:38.091",
"endDate": "0001-01-01T00:00:00"
},
{
"addrCity": "Stockton",
"addrCountry": "United States",
"addrState": "California",
"employer": "OSIsoft",
"id": "5501eb7a54355e3b8c879619",
"workType": "Internship",
"startDate": "2007-09-12T12:39:38.386",
"endDate": "0001-01-01T00:00:00"
},
我需要修改查询以匹配references =“colleage”,并且我需要获得应该匹配的列表雇主的经验。 谢谢你的帮助。
这是我到目前为止所做的,但它不能正常工作。 我提交了一份雇主名单,并将其列入名单中的第一位雇主并忽略了其他项目。
var results = client.Search<Persondb>(s => s
.From(0)
.Size(100)
.Query(q => q
.Bool(b => b
.Must(ms =>
ms.Match(mt0 => mt0.Field(f => f.FirstName).Query(searchQuery.FirstName)) &&
ms.Match(mt0 => mt0.Field(f => f.LastName).Query(searchQuery.LastName)) &&
ms.Match(mt0 => mt0.Field(f => f.IsNewUser).Query("false")) &&
ms.Match(mt0 => mt0.Field(f => f.MemberRole).Query("Ordinary")) &&
q.Nested(n => n
.Path(p => p.Reference)
.Query(qq => qq.Match(m => m.Field(f => f.Reference.First().Relationshiptype).Query(searchQuery.Type)))) &&
q.Nested(n => n
.Path(p => p.Experience)
.Query(qq => qq.Match(m => m.Field(f => f.Experience.First().Exployer).Query(searchQuery.company))))
))));
queryList = results.Documents.ToList();
感谢
{
public class Persondb
{
[String(Store = true)]
public string Id { get; set; }
[Nest.String(Store = true, Index = Nest.FieldIndexOption.Analyzed, Analyzer = "rockon", TermVector = Nest.TermVectorOption.WithPositionsOffsets)]
public string FirstName { get; set; }
[Nest.String(Store = true, Index = Nest.FieldIndexOption.Analyzed, Analyzer = "rockon", TermVector = Nest.TermVectorOption.WithPositionsOffsets)]
public string LastName { get; set; }
[Nest.String(Store = true, Index = Nest.FieldIndexOption.Analyzed, TermVector = Nest.TermVectorOption.WithPositionsOffsets)]
public string CurrentCompany { get; set; }
[Nest.String(Store = true, Index = Nest.FieldIndexOption.Analyzed, TermVector = Nest.TermVectorOption.WithPositionsOffsets)]
public string ProfileTitle { get; set; }
[Boolean(Store = true)]
public bool IsNewUser { get; set; }
[String(Store = true)]
public string MemberRole { get; set; }
[String(Store = true)]
public string ProfileUrl { get; set; }
[String(Store = true)]
public string MembershipType { get; set; }
#region
[Nested(IncludeInParent = true)]
public List<ReferenceObj> Reference { get; set; }
[Nested(IncludeInParent = true)]
public List<WorkHistoryObj> WorkHistory { get; set; }
}
[Nest.ElasticsearchType]
public class ReferenceObj
{
[String(Store = true)]
public string RelatedTo { get; set; }
[String(Store = true)]
public string RelationshipType { get; set; }
[String(Store = true)]
public string Id { get; set; }
}
[Nest.ElasticsearchType]
public class WorkHistoryObj
{
[String]
public string AddrCity { get; set; }
[String]
public string AddrCountry { get; set; }
[String]
public string AddrState { get; set; }
[String]
public string Employer { get; set; }
[String]
public string Id { get; set; }
[String]
public string WorkType { get; set; }
[String]
public string Industry { get; set; }
[Date]
public DateTime StartDate { set; get; }
[Date]
public DateTime EndDate { set; get; }
}
}
感谢
public IEnumerable<UserData> NewSearch(string memberSoid, MemberSearchQueryModel searchQuery)
{
var node = new Uri(Utilities.UrlConstants.SearchServiceUrl);
var setting = new ConnectionSettings(node);
var client = new ElasticClient(setting);
List<UserData> queryList;
var searchResponse = client.Search<Persondb>(s =>
s.Query(q => q
.Nested(n => n
.Path(p => p
.WorkHistory).Query(qq => qq
.Match(m => m.Field(f => f
.WorkHistory.FindAll(u => u
.Employer.Contains("GOOGLE INC, MICROSOFT, JOHN INC, TEAM JOBS, SALES FORCE"))))))));
queryList = searchResponse.Documents.ToList();
return queryList;
}
我也试过了,但它没有用。 感谢。