Search query nested fields


#1

Hello,

I create an index with nested fields, and I load many JSON documents in this index.

When I try to search an especific field inside nested filed, always elasticsearch return the all JSON.

I need that ES return me only the field that I try to filter.

My index is this:

{
"nested_v3": {
"aliases": {},
"mappings": {
"nested_v3": {
"properties": {
"episodio": {
"type": "nested",
"properties": {
"codi_episodi": {
"type": "integer"
},
"diagnostic": {
"type": "nested",
"properties": {
"codi": {
"type": "text",
"fields": {
"raw": {
"type": "keyword"
}
}
},
"descripcio": {
"type": "text",
"fields": {
"raw": {
"type": "keyword"
}
}
}
}
},
"tx": {
"type": "nested",
"properties": {
"obx": {
"type": "nested",
"properties": {
"obx_descripcion": {
"type": "text",
"fields": {
"raw": {
"type": "keyword"
}
}
},
"obx_valor": {
"type": "integer",
"fields": {
"raw": {
"type": "keyword"
}
}
},
"valor": {
"type": "text",
"fields": {
"raw": {
"type": "keyword"
}
}
}
}
},
"tipotx": {
"type": "text",
"fields": {
"raw": {
"type": "keyword"
}
}
},
"valor_tx": {
"type": "integer",
"fields": {
"raw": {
"type": "keyword"
}
}
}
}
}
}
},
"nhc": {
"type": "integer"
},
"product": {
"properties": {
"categories": {
"properties": {
"level1": {
"type": "text",
"fields": {
"raw": {
"type": "keyword"
}
}
},
"level2": {
"type": "text",
"fields": {
"raw": {
"type": "keyword"
}
}
}
}
}
}
}
}
}
},
"settings": {
"index": {
"creation_date": "1513593412598",
"number_of_shards": "5",
"number_of_replicas": "1",
"uuid": "SlAvr3W3QW6HD1ejcvrBzg",
"version": {
"created": "5030299"
},
"provided_name": "nested_v3"
}
}
}
}

==> My document is this:

{
"_index": "nested_v3",
"_type": "nested_v3",
"_id": "9999999",
"_version": 1,
"found": true,
"_source": {
"nhc": 9999999,
"product": [
{
"categories.level1": "Drama",
"categories.level2": "Thriller"
}
],
"episodio": [
{
"codi_episodi": 4444,
"tx": [
{
"valor_tx": 83332,
"tipotx": "General",
"obx": [
{
"obx_valor": "10",
"obx_descripcion": "Bon estat general",
"valor": "S"
},
{
"obx_valor": "11",
"obx_descripcion": "Bon estat general",
"valor": "S"
}
]
},
{
"valor_tx": 5555,
"tipotx": "Antropometria",
"obx": [
{
"obx_valor": "5",
"obx_descripcion": "Peso",
"valor": "80"
},
{
"obx_valor": "90",
"obx_descripcion": "Altura",
"valor": "195"
}
]
}
],
"diagnostic": [
{
"codi": "55",
"descripcio": "Acantosis"
},
{
"codi": "99",
"descripcio": "Faringuitis"
}
]
},
{
"codi_episodi": 1111111,
"tx": [
{
"valor_tx": 83337772,
"tipotx": "General_episodi2",
"obx": [
{
"obx_valor": "10",
"obx_descripcion": "Bon estat general_episodi2",
"valor": "S_episodi2"
},
{
"obx_valor": "11",
"obx_descripcion": "Bon estat general_episodi2",
"valor": "S_episodi2"
}
]
},
{
"valor_tx": 988888888,
"tipotx": "Antropometria_episodi2",
"obx": [
{
"obx_valor": "5",
"obx_descripcion": "Peso_episodi2",
"valor": "80"
},
{
"obx_valor": "90",
"obx_descripcion": "Altura_episodi2",
"valor": "195"
}
]
}
],
"diagnostic": [
{
"codi": "55",
"descripcio": "Artrosis_episodi2"
},
{
"codi": "99",
"descripcio": "Faringuitis Aguda_episodi2"
}
]
}
]
}
}

My query is this:

GET /nested_v3/_search
{
"query": {
"bool": {
"must": [
{
"nested": {
"path": "episodio.tx.obx",
"query": {
"bool": {
"must": [
{
"match": {
"episodio.tx.obx.obx_descripcion.raw": "Peso"
}
}
]
}
}
}
}
]
}}}


(Mike Barretta) #2

@xavi23 You have a couple of ways to customize the response you get from an ES query.

  • Response Filtering can be used to select or remove parts of the response
  • Source Filtering can be used to select or remove parts of the indexed documents (the _source metadata field) that are included in the response

(system) #3

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