#143 How to use JSON queries with Haystack using Elasticsearch?

roberto hashioka Tue 14 Jan 2014

I would like to use following JSON query with Haystack, but cannot find how to use JSON queries instead of QuerySet (as it seems there is no way to do this in QuerySet).

{

"query": {
    "filtered": {
        "filter": {
            "bool": {
                "must": [
                    {
                        "term": {
                            "django_ct": "repositories.repository"
                        }
                    },
                    {
                        "term": {
                            "status": 1
                        }
                    },
                    {
                        "term": {
                            "is_private": false
                        }
                    },
                    {
                        "term": {
                            "is_library": false
                        }
                    }
                ]
            }
        },
        "query": {
            "function_score": {
                "query": {
                    "bool": {
                        "should": [
                            {
                                "match": {
                                    "name": {
                                        "query": "hipache"
                                    }
                                }
                            },
                            {
                                "custom_boost_factor": {
                                    "boost_factor": 0.005,
                                    "query": {
                                        "multi_match": {
                                            "fields": [
                                                "name_auto^3",
                                                "name_auto.partial^2",
                                                "name_auto.partial_back",
                                                "name_auto.partial_middle"
                                            ],
                                            "query": "hipache"
                                        }
                                    }
                                }
                            }
                        ]
                    }
                },
                "script_score": {
                    "script": "_score * (1 + 10.0*log(1 + doc['pull_count'].value))"
                }
            }
        }
    }
}

}

Login or Signup to reply.