/create_nested_index.sh Secret
Created
October 31, 2012 12:01
-
-
Save imotov/3e9a2daf3e6f2b12412b to your computer and use it in GitHub Desktop.
Search articles by tag slug
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
#!/usr/bin/env bash | |
curl -XPUT http://localhost:9200/cars?pretty=true -d'{ | |
"settings": { | |
"number_of_shard": 1, | |
"number_of_replicas": 1 | |
}, | |
"mappings": { | |
"documents": { | |
"properties": { | |
"title": { | |
"type": "string", | |
"store": "yes" | |
}, | |
"tags": { | |
"type": "nested", | |
"properties": { | |
"title": { | |
"type": "string", | |
"store": "yes" | |
}, | |
"slug": { | |
"type": "string", | |
"store": "yes" | |
} | |
} | |
} | |
} | |
} | |
} | |
}' |
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
!/usr/bin/env bash | |
curl -XPOST http://localhost:9200/cars/documents/1?pretty=true -d'{ | |
"title": "Test Document 1", | |
"slug": "test-document-1", | |
"content": "<p>Some content</p>", | |
"published": "2", | |
"version": "2", | |
"tags": [ | |
{ | |
"name": "Cars", | |
"slug": "cars", | |
"type": 101 | |
}, | |
{ | |
"name": "News", | |
"slug": "news", | |
"type": 102 | |
} | |
] | |
}' | |
curl -XPOST http://localhost:9200/cars/documents/2?pretty=true -d'{ | |
"title": "Test Document 2", | |
"slug": "test-document-2", | |
"content": "<p>Some content</p>", | |
"published": "2", | |
"version": "2", | |
"tags": [ | |
{ | |
"name": "Cars", | |
"slug": "cars", | |
"type": 101 | |
}, | |
{ | |
"name": "Reviews", | |
"slug": "reviews", | |
"type": 102 | |
} | |
] | |
}' | |
curl -XPOST http://localhost:9200/cars/documents/3?pretty=true -d'{ | |
"title": "Test Document 3", | |
"slug": "test-document-3", | |
"content": "<p>Some content</p>", | |
"published": "2", | |
"version": "2", | |
"tags": [ | |
{ | |
"name": "Cars", | |
"slug": "cars", | |
"type": 101 | |
}, | |
{ | |
"name": "Reviews", | |
"slug": "reviews", | |
"type": 102 | |
} | |
] | |
}' | |
curl -XPOST http://localhost:9200/cars/documents/4?pretty=true -d'{ | |
"title": "Test Document 4", | |
"slug": "test-document-4", | |
"content": "<p>Some content</p>", | |
"published": 0, | |
"version": 2, | |
"tags": [ | |
{ | |
"name": "Cars", | |
"slug": "cars", | |
"type": 101 | |
}, | |
{ | |
"name": "Reviews", | |
"slug": "reviews", | |
"type": 102 | |
} | |
] | |
}' | |
curl -XPOST http://localhost:9200/cars/documents/5?pretty=true -d'{ | |
"title": "Test Document 5", | |
"slug": "test-document-5", | |
"content": "<p>Some content</p>", | |
"published": "2", | |
"version": "2", | |
"tags": [ | |
{ | |
"name": "Cars", | |
"slug": "cars", | |
"type": 101 | |
}, | |
{ | |
"name": "Reviews", | |
"slug": "reviews", | |
"type": 102 | |
} | |
] | |
}' |
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
#!/usr/bin/env bash | |
curl -XGET http://localhost:9200/cars/documents/_search?pretty=true -d'{ | |
"query": { | |
"filtered": { | |
"query": { | |
"match_all": {} | |
}, | |
"filter": { | |
"bool": { | |
"must": [ | |
{ | |
"range": { "published": { "gt": 0 } } | |
}, | |
{ | |
"nested": { | |
"path": "tags", | |
"query": { | |
"filtered": { | |
"query": { | |
"match_all": {} | |
}, | |
"filter": { | |
"and": [ | |
{ | |
"term": { | |
"tags.slug": "reviews" | |
} | |
} | |
] | |
} | |
} | |
} | |
} | |
} | |
] | |
} | |
} | |
} | |
}, | |
"from": 0, | |
"size": 10 | |
}' |
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
#!/usr/bin/env bash | |
curl -XGET http://localhost:9200/cars/documents/_search?pretty=true -d'{ | |
"query": { | |
"filtered": { | |
"query": { | |
"match_all": {} | |
}, | |
"filter": { | |
"nested": { | |
"path": "tags", | |
"query": { | |
"filtered": { | |
"query": { | |
"match_all": {} | |
}, | |
"filter": { | |
"and": [ | |
{ | |
"term": { | |
"tags.slug": "reviews" | |
} | |
} | |
] | |
} | |
} | |
} | |
} | |
} | |
} | |
}, | |
"from": 0, | |
"size": 1 | |
}' |
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
#!/usr/bin/env bash | |
curl -XGET http://localhost:9200/cars/documents/_search?pretty=true -d'{ | |
"fields": ["title", "slug", "tags"], | |
"query": { | |
"filtered": { | |
"query": { | |
"match_all": {} | |
}, | |
"filter": { | |
"and": [{ | |
"nested": { | |
"path": "tags", | |
"filter": { | |
"term": { | |
"tags.slug": ["cars"] | |
} | |
} | |
} | |
}, { | |
"nested": { | |
"path": "tags", | |
"filter": { | |
"term": { | |
"tags.slug": ["news"] | |
} | |
} | |
} | |
}] | |
} | |
} | |
} | |
}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment