django-haystack / django-haystack/django-haystack
How to index postgres' JSONField?
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 3.7k
- Forks
- 1.3k
- Avg merge
- 3h 18m
- Merged PRs (30d)
- 3
Description
Hi, I'm not sure if this is something I failed to find/understand from the docs or if it is an entirely new feature.
Basically I have a project in which models have a 'custom property' system powered by Postgres' JSONField. This allows users to add a json document to the set of properties of each object.
I'd like to be able to search (via ES) those fields like they were any other property.
As an example:
# models.py
class MyModel(models.Model):
name = models.CharField()
attrs = postgres.fields.JSONField(default=dict)
# how I'd expect ES documents to look like:
{
...,
"name": "banana",
"attrs" : { "fruitColor": "yellow", "growsOnTrees": true}
},
{
...,
"name": "samuel",
"attrs" : { "friends": ["mark", "francesca", "luke"], "birthday": "10/10/1990"}
}
What type of SearchField should I use?
Thanks!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue provides a models.py example using Django's PostgreSQL JSONField and asks how to expose its contents to Elasticsearch. Start by checking the search-field documentation and the JSONField integration, then determine whether the expected nested fields are supported or need documentation. Done means a documented, verified way to index and search these values, or a clearly scoped feature request.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- django, elasticsearch, postgresql, python
- Domain
- backend, databases, search
- Issue type
- Documentation
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100