-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Terms Aggregation KeyAsString is always null #2393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Amir, I think the issue you are having is because your guidVal property is being On Sat, Nov 19, 2016 at 9:34 AM, Amir Sasson [email protected]
Doug Nelson |
How can the analyzer be disabled for this aggregation only? On Nov 19, 2016 19:07, "djnelson9715" [email protected] wrote:
|
if look at the mapping for this type, yourindex/_mapping
you need to add the index setting. This is very good practice to use On Sat, Nov 19, 2016 at 11:15 AM, Amir Sasson [email protected]
Doug Nelson |
The problem as @djnelson9715 has pointed out, is that the void Main()
{
var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
var connectionSettings = new ConnectionSettings(pool);
var client = new ElasticClient(connectionSettings);
var indexName = "github-issue-2393";
client.Index(new TestClass
{
guidVal = new Guid("034a7b09-9fee-4f63-a87f-4592edd9560d")
}, i => i.Refresh().Index(indexName));
var aggResponse = client.Search<TestClass>(s => s
.Index(indexName)
.Aggregations(a => a
.Terms("distinc_bus", ad => ad
.Field(t => t.guidVal)
)
)
);
}
public class TestClass
{
public Guid guidVal { get; set; }
} This returns the following json for the search response {
"took" : 41,
"timed_out" : false,
"_shards" : {
"total" : 2,
"successful" : 2,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 1.0,
"hits" : [ {
"_index" : "github-issue-2393",
"_type" : "testclass",
"_id" : "AVi0L-rWLtlOUI4Y790E",
"_score" : 1.0,
"_source" : {
"guidVal" : "034a7b09-9fee-4f63-a87f-4592edd9560d"
}
} ]
},
"aggregations" : {
"distinc_bus" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [ {
"key" : "034a7b09",
"doc_count" : 1
}, {
"key" : "4592edd9560d",
"doc_count" : 1
}, {
"key" : "4f63",
"doc_count" : 1
}, {
"key" : "9fee",
"doc_count" : 1
}, {
"key" : "a87f",
"doc_count" : 1
} ]
}
}
} You can see that each key is actually a subsection of the guid sent in. If you check out the mapping with var mappingResponse = client.GetMapping<TestClass>(m => m.Index(indexName)); You'll see that the field has been set up as an analyzed string {
"github-issue-2393" : {
"mappings" : {
"testclass" : {
"properties" : {
"guidVal" : {
"type" : "string"
}
}
}
}
}
} To index it as a not_analyzed string field, you can map it as such with client.CreateIndex(indexName, c => c
.Mappings(m => m
.Map<TestClass>(mm => mm
// let NEST infer the Elasticsearch types from the POCO type...
.AutoMap()
// ...now override any automappings that we want to explicitly set
.Properties(p => p
.String(s => s
.Name(n => n.guidVal)
.NotAnalyzed()
)
)
)
)
); You'll need to create a new index to do this and reindex your documents into it. You can use the Reindex API to do this; construct the destination index first with the above mapping. If you need both an analyzed and not_analyzed form of Hope that helps! |
Meant to add that |
NEST/Elasticsearch.Net version:2.4.6
Elasticsearch version:
"version" : {
"number" : "2.4.1",
"build_hash" : "c67dc32e24162035d18d6fe1e952c4cbcbe79d16",
"build_timestamp" : "2016-09-27T18:57:55Z",
"build_snapshot" : false,
"lucene_version" : "5.5.2"
},
Description of the problem including expected versus actual behavior:
Steps to reproduce:
for example object like : {name: 'SOME NAME' guidVal: '034a7b09-9fee-4f63-a87f-4592edd9560d'}
The text was updated successfully, but these errors were encountered: