Skip to content

Instantly share code, notes, and snippets.

@zhenghao1
Created August 11, 2012 17:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhenghao1/3325910 to your computer and use it in GitHub Desktop.
Save zhenghao1/3325910 to your computer and use it in GitHub Desktop.
Product listing using elastic search with python's pyes
fields = [
"_id", "key", "content.name", "content.brand", "content.season",
"content.description", "content.status", "content.category"
]
typeFilter = TermFilter("type", "product")
deleteFilter = TermFilter("deleted", False)
f = ANDFilter([typeFilter, deleteFilter])
query = FilteredQuery(MatchAllQuery(), f)
search = Search(query, start=paging['skip'], size=paging['take'],
fields=fields)
results = request.es.conn.search(search)
{
"product": {
"_type": {"store": "yes"},
"_source": {"compress": true},
"index_analyzer": "standard",
"search_analyzer": "standard",
"dynamic_date_formats": ["date_time_no_millis", "date_optional_time"],
"properties": {
"_id": {"type": "string", "store": "yes", "index": "not_analyzed"},
"key": {"type": "string", "store": "yes"},
"content": {
"type": "object",
"path": "just_name",
"properties": {
"key": {"type": "string", "store": "yes"},
"name": {"type": "string", "store": "yes", "index_name": "name"},
"description": {"type": "string", "store": "yes", "index_name": "description"},
"brand": {
"type": "object",
"index_name": "brand",
"properties": {
"abbreviation": {"type": "string", "store": "yes", "index_name": "brand_abbreviation"},
"name": {"type": "string", "store": "yes", "index_name": "brand_name"}
}
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment