Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to filter the response of opensearch API in the request?

I want to query an opensearch index and to retrieve only the _source inside the hits tag. I tried to make the request in Postman like:

GET: http://localhost:9200/my_index/_search?q="product1234"?format=json?filter_path=hits.hits._source

but this also gets me the metadata and all the other informative fields, like:

{
    "took": 17,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 44,
            "relation": "eq"
        },
        "max_score": 4.2769747,
        "hits": [
            {
                "_index": "os_fcpq_index",
                "_id": "300",
                "_score": 4.2769747,
                "_source": {...

I want to be able to retrieve a json that contains only the values that are inside the _source tag, like:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

[{'_source': {'product_id': '1234'...}}]

I also looked over the opensearch documentation and it is possible to use the argument filter_path, but in my example it seems I am missing something…

>Solution :

You have too many ? in your URL, you need to separate each query string parameter with & instead of ?

GET: http://localhost:9200/my_index/_search?q="product1234"&format=json&filter_path=hits.hits._source
                                                           ^           ^
                                                           |           |
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading