0

I am very new in ES and I am trying to figure out some things.

I did a basic query this way

GET _search
{
  "query": {
    "match_all": {}
  }
}

and I got this...

{
  "took": 7,
  "timed_out": false,
  "_shards": {
    "total": 768,
    "successful": 768,
    "failed": 0
  },
  "hits": {
    "total": 456,
    "max_score": 1,
    "hits": [
      {
        "_index": "sometype_1",
        "_type": "sometype",
        "_id": "12312321312312",
        "_score": 1,
        "_source": {
          "readModel": {
            "id": "asdfqwerzcxv",
            "status": "active",
            "hidden": false
          },
          "model": {
            "id": "asdfqwerzcxv",
            "content": {
              "objectId": "421421312312",
              "message": "hello world",
              ..... //the rest of the object...

So right now I want to get the object with id asdfqwerzcxv and I did this:

GET _search
{
    "query": {
        "match" : {
            "id" :"asdfqwerzcxv"

        }
    }
}

But of course is not working... I also tried to make the whole route like:

GET _search
{
    "query": {
        "match" : {
            "_source" :{
              "readModel" : {
                 "id": "asdfqwerzcxv"      
              }
            }

        }
    }
}

But no luck...

is there a way to do this? could someone help me?

Thanks

jpganz18
  • 5,508
  • 17
  • 66
  • 115

1 Answers1

2

You need to use the full-qualified field name, try this:

GET _search
{
    "query": {
        "match" : {
            "readModel.id" :"asdfqwerzcxv"
                 ^
                 |
              add this
        }
    }
}
Val
  • 207,596
  • 13
  • 358
  • 360
  • Thats fantastic! thanks, is it the same way for update it? like change a field value... – jpganz18 Nov 28 '18 at 14:07
  • It depends on how you want to update the document. Do you want to reindex it completely or just change the value of a single field? (I also suggest you create a different question since this is a different subject) – Val Nov 28 '18 at 14:11
  • Would it be a benefit if using `term` query instead of `match` query? – a.l. Nov 28 '18 at 14:29
  • Most of the time, using `match` is recommended as match is smart enough to resort to term query if possible depending on the field mapping – Val Nov 28 '18 at 14:32
  • thanks, can you help me with that other one please? https://stackoverflow.com/questions/53521862/update-information-in-elastic-search – jpganz18 Nov 28 '18 at 14:36