I used elasticsearch-dsl==5.2.0
, elasticsearch==5.3.0
and Django==1.8.15
.
Django model:
class Item(models.Model):
price = models.DecimalField(default=0)
def to_search(self):
return DocItem(
meta={'id': self.id},
price=self.price
)
DocType class:
class DocItem(DocType):
price = Integer()
FacetedSearch class:
class ItemSearch(FacetedSearch):
index = 'item'
doc_types = [DocItem, ]
fields = ['price']
When I need to search all items with price == 5.0
, I do the next:
search = ItemSearch().search()
result = search.filter('match', price=5.0).execute()
Question:
How can I search all items with price in range: 1.0 < price <= 5.0 ?
You can do it like this:
search = ItemSearch().search()
result = search.filter('range', price={'gt': 1, 'lte': 5.0}).execute()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With