I am attempting to perform a query with filters. I can get it to filter on some properties but not the one I need. Here is my model:
public class IndexItem
{
public DateTime CreatedDate { get; set; }
[ElasticProperty(Index = FieldIndexOption.Analyzed)]
public String Name { get; set; }
[ElasticProperty(Index = FieldIndexOption.NotAnalyzed)]
public String Role { get; set; }
public bool ExcludeFromSearch { get; set; }
}
The query I start off with is:
var esQuery = Query<IndexItem>.QueryString(x => x.OnFields(f => f.Name).Query(String.Format("{0}*", query)).Boost(1.2));
If I filter on CreatedDate or ExcludeFromSearch it works like I would think, But I cannot get it to work for Role.
filter.Add(Filter<IndexItem>.Term(x => x.CreatedDate, searchDate)); // Works
filter.Add(Filter<IndexItem>.Term(x => x.Role, role)); // Never Returns a result
var searchResults = client.Search<IndexItem>(s => s
.Types(typeof(IndexItem))
.From(start)
.Size(count)
.Query(esQuery)
.Filter(x => x.And(filter.ToArray()))
); // Returns empty if I filter by Role, but works if i filter by CreatedDate
The only difference I can see is that Role has the annotation [ElasticProperty(Index = FieldIndexOption.NotAnalyzed)]. Does this make it not allowed to be filtered by?
Here is an example output for a query I put in the browser:
{"took":47,"timed_out":false,"_shards":{"total":10,"successful":10,"failed":0},"hits":{"total":1,"max_score":5.9272537,"hits":[{"_index":"default-index","_type":"indexitem","_id":"3639","_score":5.9272537,"_source":{
"properties": {
"MainBody": "Test Role Search"
},
"id": "3639",
"createdDate": "2015-05-08T14:34:33",
"name": "Role Test",
"url": "/my-role-test/",
"role": "Admin",
"excludeFromSearch": false
}}]}}