0

I'm working with Elasticsearch, currently I have a struct like that

{
    "took": 2,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "failed": 0
    },
    "hits": {
        "total": 1,
        "max_score": 1,
        "hits": [
            {
                "_index": "999999",
                "_type": "content",
                "_id": "NmYTku",
                "_score": 1,
                "_source": {
                    "internal_id": "NmYTk4",
                    "external_id": "Ga_UI502",
                    "
                    "images": [
                        {
                            "uri_id": "2939306",
                            "url": "14mast_head.jpg",
                            "type": "Masthead",
                            "orientation": "Landscape",
                            "x_resolution": 3280,
                            "y_resolution": 1480
                        },
                        {
                            "uri_id": "Galavision/POST_poster/2939306",
                            "url": "140603_29un_erro_poster.jpg",
                            "type": "Poster",
                            "orientation": "Portrait",
                            "x_resolution": 720,
                            "y_resolution": 405
                        },
                        {
                            "uri_id": "Galavision/POST_poster_title/2939306",
                            "url": "140603_29un_erro_poster_title.jpg",
                            "type": "PosterWithTitle",
                            "orientation": "Portrait",
                            "x_resolution": 924,
                            "y_resolution": 518
                        },
                        {
                            "uri_id": "Galavision/POST_poster_cover/2939306",
                            "url": "140603_29poster_cover.jpg",
                            "type": "Poster",
                            "orientation": "Landscape",
                            "x_resolution": 600,
                            "y_resolution": 868
                        }
                    ]
                }
            }
        ]
    }
}

I was wondering, how can I get only one value from my array e.g. I want to have only the images with oritentation on Landscape and type Poster. I tried with This query but it only returns me all the image elements.

{
    "query": {
        "filtered": {
            "filter": { "term":{"_id":"NmYTku"} }
    }
},
  "_source": ["images"]
}

I don't have idea how do a filter on the elements

2 Answers 2

2

Are you using nested or child fields for the images? If not, that doc is actually being indexed like:

...
images.uri_id = [1, 2, 3, 4, etc..]
images.url = [1, 2, 3, 4, etc..]
images.type = [1, 2, 3, 4, etc..]
...

so the distinction between individual elements is gone. Try giving this a read: http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/complex-core-fields.html

If you don't need to query, why not just filter out the ones you like client side?

Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

{
  "filtered": {
    "query": {
      "match": { "term": "_id" : "NmYTku" }
},
  "_source": [images]{
    "orientation": "landscape",
    "type": "Poster",
  }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.