Created
March 17, 2017 22:39
-
-
Save anonymous/83bc2b1bfa0ac0d295d42297e1d76c00 to your computer and use it in GitHub Desktop.
test documents
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
PUT newindex3 | |
{ | |
"mappings": { | |
"article": { | |
"properties": { | |
"content": { | |
"type": "text", | |
"fields": { | |
"keyword": { | |
"type": "keyword", | |
"ignore_above": 256 | |
} | |
} | |
}, | |
"title": { | |
"type": "text", | |
"fields": { | |
"keyword": { | |
"type": "keyword", | |
"ignore_above": 256 | |
} | |
} | |
}, | |
"tags": { | |
"type": "nested", | |
"properties": { | |
"tagName": { | |
"type": "text", | |
"fields": { | |
"raw": { | |
"type": "keyword" | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
POST newindex3/article/1 | |
{ | |
"title": "Some Title", | |
"content": "FIY Fix yourself", | |
"tags": [ | |
{ | |
"tagName": "Fix it yourself" | |
}, | |
{ | |
"tagName": "customer tips" | |
}, | |
{ | |
"tagName": "competition" | |
} | |
] | |
} | |
POST newindex3/article/2 | |
{ | |
"title": "Some Title", | |
"content": "some content FIY", | |
"tags": [ | |
{ | |
"tagName": "how to" | |
}, | |
{ | |
"tagName": "customer tips" | |
}, | |
{ | |
"tagName": "competition" | |
} | |
] | |
} | |
POST newindex3/article/3 | |
{ | |
"title": "Some Title 3", | |
"content": "some content 3", | |
"tags": [ | |
{ | |
"tagName": "Fix it yourself" | |
} | |
{ | |
"tagName": "competition"some | |
} | |
] | |
} | |
POST newindex3/article/4 | |
{ | |
"title": "Some Title 4", | |
"content": "some content 4", | |
"tags": [ | |
{ | |
"tagName": "Fix it yourself" | |
}, | |
{ | |
"tagName": "customer tips" | |
} | |
] | |
} | |
//will return those documents with FIY in the title or content fields, and those with the tag "competition" (2 Records) | |
GET newindex3/_search | |
{ | |
"query": { | |
"bool": { | |
"must": [ | |
{ | |
"multi_match": { | |
"query": "FIY", | |
"fields": [ | |
"title", | |
"content" | |
] | |
} | |
}, | |
{ | |
"nested": { | |
"query": { | |
"terms": { | |
"tags.tagName": [ | |
"competition" | |
] | |
} | |
}, | |
"path": "tags" | |
} | |
} | |
] | |
} | |
} | |
} | |
//SHOULD return those documents with FIY in the title or content fields, and those with the tag "competition" (2 Records) | |
// then aggregte the tags so SHOULD show | |
how to (1) | |
Fix it yourself (1) | |
customer(2) | |
competition(2) | |
GET newindex3/_search | |
{ | |
"from": 1, | |
"size": 10, | |
"aggs": { | |
"tags": { | |
"nested": { | |
"path": "tags" | |
}, | |
"aggs": { | |
"tags-tagnames": { | |
"terms": { | |
"field": "tags.tagName.raw" | |
} | |
} | |
} | |
} | |
}, | |
"query": { | |
"bool": { | |
"must": [ | |
{ | |
"multi_match": { | |
"query": "FIY", | |
"fields": [ | |
"title", | |
"content" | |
] | |
} | |
}, | |
{ | |
"nested": { | |
"query": { | |
"terms": { | |
"tags.tagName": [ | |
"competition" | |
] | |
} | |
}, | |
"path": "tags" | |
} | |
} | |
] | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fixed issue on lines 85 (missing comma) and 87 (removed
some
): https://gist.github.com/anonymous/83bc2b1bfa0ac0d295d42297e1d76c00#file-gistfile1-txt-L85-L87