Last active
August 10, 2016 17:45
-
-
Save nguyenhoaibao/9ec83ec5ee24aa6a2902 to your computer and use it in GitHub Desktop.
Elasticsearch Query Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"query": { | |
"filtered": { | |
"filter": { | |
"bool": { | |
"must": [ | |
{ | |
"or": [ | |
{ | |
"nested": { | |
"path": "snippets", | |
"filter": { | |
"bool": { | |
"must": [ | |
{ | |
"or": [ | |
{ | |
"term": { | |
"snippets.sentiment": "3" | |
} | |
}, | |
{ | |
"term": { | |
"snippets.sentiment": "1" | |
} | |
} | |
] | |
} | |
] | |
} | |
} | |
} | |
}, | |
{ | |
"not": { | |
"nested": { | |
"path": "snippets", | |
"filter": { | |
"match_all": {} | |
} | |
} | |
} | |
} | |
] | |
}, | |
{ | |
"range": { | |
"publishedDate": { | |
"gte": "2014-10-01T00:00:00", | |
"lte": "2015-02-27T23:59:59" | |
} | |
} | |
}, | |
{ | |
"or": [ | |
{ | |
"missing": { | |
"field": "isDeleted" | |
} | |
}, | |
{ | |
"term": { | |
"isDeleted": 0 | |
} | |
} | |
] | |
} | |
] | |
} | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"query": { | |
"filtered": { | |
"filter": { | |
"bool": { | |
"must": [ | |
{ | |
"or": [ | |
{ | |
"nested": { | |
"path": "snippets", | |
"filter": { | |
"bool": { | |
"must": { | |
"or": [ | |
{ | |
"term": { | |
"snippets.sentiment": "positive" | |
} | |
}, | |
{ | |
"term": { | |
"snippets.sentiment": "negative" | |
} | |
}, | |
{ | |
"term": { | |
"snippets.sentiment": "neutral" | |
} | |
} | |
] | |
} | |
} | |
} | |
} | |
}, | |
{ | |
"not": { | |
"nested": { | |
"path": "snippets", | |
"filter": { | |
"match_all": {} | |
} | |
} | |
} | |
} | |
] | |
}, | |
{ | |
"range": { | |
"meta.created_time": { | |
"gte": "2015-10-14T00:00:00.000Z", | |
"lte": "2015-10-14T23:59:59.999Z" | |
} | |
} | |
} | |
] | |
} | |
} | |
} | |
}, | |
"sort": { | |
"meta.inserted_time": { | |
"order": "desc" | |
} | |
}, | |
"aggs": { | |
"aggs_by_sentiment_date_range": { | |
"nested": { | |
"path": "snippets" | |
}, | |
"aggs": { | |
"sentiment": { | |
"terms": { | |
"field": "snippets.sentiment" | |
}, | |
"aggs": { | |
"date_range": { | |
"reverse_nested": {}, | |
"aggs": { | |
"ddd": { | |
"date_histogram": { | |
"field": "meta.created_time", | |
"interval": "day", | |
"format": "yyyy-MM-dd", | |
"min_doc_count": 0, | |
"extended_bounds": { | |
"min": "2015-10-14", | |
"max": "2015-10-14" | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"query": { | |
"filtered": { | |
"filter": { | |
"bool": { | |
"must": [ | |
{ | |
"range": { | |
"meta.created_time": { | |
"gte": "2016-02-27T17:00:00.000Z", | |
"lte": "2016-03-03T16:59:59.000Z" | |
} | |
} | |
}, | |
{ | |
"or": [ | |
{ | |
"nested": { | |
"path": "snippets", | |
"filter": { | |
"bool": { | |
"must": [ | |
{ | |
"or": [ | |
{ | |
"term": { | |
"snippets.sentiment": "negative" | |
} | |
}, | |
{ | |
"term": { | |
"snippets.sentiment": "positive" | |
} | |
}, | |
{ | |
"term": { | |
"snippets.sentiment": "neutral" | |
} | |
} | |
] | |
} | |
] | |
} | |
} | |
} | |
}, | |
{ | |
"not": { | |
"nested": { | |
"path": "snippets", | |
"filter": { | |
"match_all": [] | |
} | |
} | |
} | |
} | |
] | |
}, | |
{ | |
"or": [ | |
{ | |
"term": { | |
"location.city_code": "br_vt" | |
} | |
}, | |
{ | |
"term": { | |
"location.city_code": "da_nang" | |
} | |
}, | |
{ | |
"term": { | |
"location.city_code": "ha_nam" | |
} | |
}, | |
{ | |
"term": { | |
"location.city_code": "ha_noi" | |
} | |
}, | |
{ | |
"term": { | |
"location.city_code": "ha_tinh" | |
} | |
}, | |
{ | |
"term": { | |
"location.city_code": "hai_phong" | |
} | |
}, | |
{ | |
"term": { | |
"location.city_code": "ho_chi_minh" | |
} | |
}, | |
{ | |
"term": { | |
"location.city_code": "nghe_an" | |
} | |
}, | |
{ | |
"term": { | |
"location.city_code": "ninh_binh" | |
} | |
}, | |
{ | |
"term": { | |
"location.city_code": "quang_ngai" | |
} | |
}, | |
{ | |
"term": { | |
"location.city_code": "thai_binh" | |
} | |
}, | |
{ | |
"term": { | |
"location.city_code": "thanh_hoa" | |
} | |
}, | |
{ | |
"term": { | |
"location.city_code": "thua_thien_hue" | |
} | |
}, | |
{ | |
"term": { | |
"location.city_code": "tra_vinh" | |
} | |
}, | |
{ | |
"missing": { | |
"field": "location" | |
} | |
} | |
] | |
} | |
], | |
"must_not": { | |
"query": { | |
"query_string": { | |
"fields": [ | |
"title.folded", | |
"content.folded", | |
"share_content.folded", | |
"post.title.folded", | |
"post.content.folded", | |
"post.share_content.folded" | |
], | |
"query": "\"tiki taka\" \"tikitaka\" \"xaytruong.org\"" | |
} | |
} | |
} | |
} | |
} | |
} | |
}, | |
"aggs": { | |
"types": { | |
"terms": { | |
"field": "_type" | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment