Search in array of object not display results


(Lukáš Vlček) #1

Hello, please i have an map Project:
{
"id": {
"type": "integer",
"index": "not_analyzed"
},
"accountId": {
"type": "integer",
"index": "not_analyzed"
},
"clientId": {
"type": "integer",
"index": "not_analyzed"
},
"ownerId": {
"type": "integer",
"index": "not_analyzed"
},
"implementerId": {
"type": "integer",
"index": "not_analyzed"
},
"name": {
"type": "string",
"index": "analyzed",
"analyzer": "hunspell_cs"
},
"description": {
"type": "string",
"index": "analyzed",
"analyzer": "hunspell_cs"
},
"visible": {
"type": "integer",
"index": "not_analyzed"
},
"created": {
"type": "date",
"index": "not_analyzed"
},
"deadline": {
"type": "date",
"index": "not_analyzed"
},
"users": {
"type": "nested",
"properties": {
"id": { "type": "integer" },
"name": { "type": "string" }
}
}
}

and document is filled as this:
{
"_index": "es-main",
"_type": "Project",
"_id": "24",
"_score": 1,
"_source": {
"id": 24,
"accountId": 1,
"clientId": null,
"ownerId": 2,
"implementerId": 7,
"name": "IL - Integrated life",
"description": null,
"visible": 1,
"created": "2016-11-24",
"deadline": "2016-11-24",
"users": [
{
"id": 2,
"name": "Jakub Helešic"
},
{
"id": 7,
"name": "Josef Andrle"
},
{
"id": 10,
"name": "Michaela Niečová"
},
{
"id": 9,
"name": "Roman Kratochvíl"
}
],
"_is_Project": 1
}
}

how to search by users.id = 2 ?

my query does not display anything. query is :
GET /es-main/Project/_search
{
"query" : {
"bool": {
"must": [
{ "match": { "users.id": 2} }
]
}
}
}

Thanks all for reply


(Nilabh Sagar) #2

You will have to use nested query as below
POST /es-main/Project/_search

{
  "query": {
    "nested": {
      "path": "users",
      "query": {
        "bool": {
          "must": {
            "match": {
              "users.id": 2
            }
          }
        }
      }
    }
  }
}

You can read more about nested query here

You ca also use inner_hits to extract the matching inner nested docs.


(Lukáš Vlček) #3

yes, thanks you very much !!!


(system) #4

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.