Elasticsearch Aggregation on Array of Objects with same properties in result












0















I have below document structure.



 {"tagsData": [
{
"hashtag": "computer",
"displayName": "Computer",
"urlKeyword": "computer"
},
{
"hashtag": "artificialIntelligence",
"displayName": "Artificial Intelligence",
"urlKeyword": "artificial-intelligence"
}
]}


My requirement is to apply aggregation on hashtag field and get the result like below



 {"aggregations": {
"tags": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "computer",
"displayName": "Computer",
"urlKeyword": "computer"
"doc_count": 1
},
{
"key": "artificialIntelligence",
"displayName": "Artificial Intelligence",
"urlKeyword": "artificial-intelligence"
"doc_count": 1
}]}
}}


Elasticsearch version 5.3
Please let me know know how can I achieve this? What should be the mapping and query?



EDIT



Mapping that I am trying.



{
"test": {
"properties" : {
"tagsData" : {
"type" : "object",
"properties": {
"hashtag" : {"type": "keyword", "index": "not_analyzed"},
"displayName" : {"type": "keyword", "index": "not_analyzed"},
"urlKeyword" : {"type": "keyword", "index": "not_analyzed"}
}
}
}
}
}









share|improve this question

























  • Could you add the mapping details. Is tagsData of nested type?

    – Kamal
    Nov 13 '18 at 8:10











  • @Kamal Please check. Added mapping.

    – vipul kumar
    Nov 13 '18 at 8:56
















0















I have below document structure.



 {"tagsData": [
{
"hashtag": "computer",
"displayName": "Computer",
"urlKeyword": "computer"
},
{
"hashtag": "artificialIntelligence",
"displayName": "Artificial Intelligence",
"urlKeyword": "artificial-intelligence"
}
]}


My requirement is to apply aggregation on hashtag field and get the result like below



 {"aggregations": {
"tags": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "computer",
"displayName": "Computer",
"urlKeyword": "computer"
"doc_count": 1
},
{
"key": "artificialIntelligence",
"displayName": "Artificial Intelligence",
"urlKeyword": "artificial-intelligence"
"doc_count": 1
}]}
}}


Elasticsearch version 5.3
Please let me know know how can I achieve this? What should be the mapping and query?



EDIT



Mapping that I am trying.



{
"test": {
"properties" : {
"tagsData" : {
"type" : "object",
"properties": {
"hashtag" : {"type": "keyword", "index": "not_analyzed"},
"displayName" : {"type": "keyword", "index": "not_analyzed"},
"urlKeyword" : {"type": "keyword", "index": "not_analyzed"}
}
}
}
}
}









share|improve this question

























  • Could you add the mapping details. Is tagsData of nested type?

    – Kamal
    Nov 13 '18 at 8:10











  • @Kamal Please check. Added mapping.

    – vipul kumar
    Nov 13 '18 at 8:56














0












0








0








I have below document structure.



 {"tagsData": [
{
"hashtag": "computer",
"displayName": "Computer",
"urlKeyword": "computer"
},
{
"hashtag": "artificialIntelligence",
"displayName": "Artificial Intelligence",
"urlKeyword": "artificial-intelligence"
}
]}


My requirement is to apply aggregation on hashtag field and get the result like below



 {"aggregations": {
"tags": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "computer",
"displayName": "Computer",
"urlKeyword": "computer"
"doc_count": 1
},
{
"key": "artificialIntelligence",
"displayName": "Artificial Intelligence",
"urlKeyword": "artificial-intelligence"
"doc_count": 1
}]}
}}


Elasticsearch version 5.3
Please let me know know how can I achieve this? What should be the mapping and query?



EDIT



Mapping that I am trying.



{
"test": {
"properties" : {
"tagsData" : {
"type" : "object",
"properties": {
"hashtag" : {"type": "keyword", "index": "not_analyzed"},
"displayName" : {"type": "keyword", "index": "not_analyzed"},
"urlKeyword" : {"type": "keyword", "index": "not_analyzed"}
}
}
}
}
}









share|improve this question
















I have below document structure.



 {"tagsData": [
{
"hashtag": "computer",
"displayName": "Computer",
"urlKeyword": "computer"
},
{
"hashtag": "artificialIntelligence",
"displayName": "Artificial Intelligence",
"urlKeyword": "artificial-intelligence"
}
]}


My requirement is to apply aggregation on hashtag field and get the result like below



 {"aggregations": {
"tags": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "computer",
"displayName": "Computer",
"urlKeyword": "computer"
"doc_count": 1
},
{
"key": "artificialIntelligence",
"displayName": "Artificial Intelligence",
"urlKeyword": "artificial-intelligence"
"doc_count": 1
}]}
}}


Elasticsearch version 5.3
Please let me know know how can I achieve this? What should be the mapping and query?



EDIT



Mapping that I am trying.



{
"test": {
"properties" : {
"tagsData" : {
"type" : "object",
"properties": {
"hashtag" : {"type": "keyword", "index": "not_analyzed"},
"displayName" : {"type": "keyword", "index": "not_analyzed"},
"urlKeyword" : {"type": "keyword", "index": "not_analyzed"}
}
}
}
}
}






elasticsearch elasticsearch-5






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 8:55







vipul kumar

















asked Nov 13 '18 at 7:54









vipul kumarvipul kumar

11




11













  • Could you add the mapping details. Is tagsData of nested type?

    – Kamal
    Nov 13 '18 at 8:10











  • @Kamal Please check. Added mapping.

    – vipul kumar
    Nov 13 '18 at 8:56



















  • Could you add the mapping details. Is tagsData of nested type?

    – Kamal
    Nov 13 '18 at 8:10











  • @Kamal Please check. Added mapping.

    – vipul kumar
    Nov 13 '18 at 8:56

















Could you add the mapping details. Is tagsData of nested type?

– Kamal
Nov 13 '18 at 8:10





Could you add the mapping details. Is tagsData of nested type?

– Kamal
Nov 13 '18 at 8:10













@Kamal Please check. Added mapping.

– vipul kumar
Nov 13 '18 at 8:56





@Kamal Please check. Added mapping.

– vipul kumar
Nov 13 '18 at 8:56












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53276257%2felasticsearch-aggregation-on-array-of-objects-with-same-properties-in-result%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53276257%2felasticsearch-aggregation-on-array-of-objects-with-same-properties-in-result%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Full-time equivalent

さくらももこ

13 indicted, 8 arrested in Calif. drug cartel investigation