Fields in the nested filter

Hi All,

My Mappings
{
"response": {
"properties": {
"rtext": {
"type": "nested",
"properties": {
"textmapid": {
"type": "integer"
},
"textvalue": {
"type": "string"
}
}
}
}
}
}

Sample data

{
"rtext" : [
{
"textmapid" : 1,
"textvalue" : "Jennifer"
},
{
"textmapid" : 2,
"textvalue" : "Adam"
}
]
},

{
"rtext" : [
{
"textmapid" : 1,
"textvalue" : "John"
},
{
"textmapid" : 2,
"textvalue" : "A"
}
]
}

Query
{
"fields": [
"rtext.textvalue"
],
"filter": {
"bool": {
"must": [
{
"nested": {
"path": "rtext",
"query": {
"bool": {
"must": [
{
"term": {
"rtext.textmapid": 1
}
}
]
}
}
}
}
]
}
}
}

My Query comes back hits: [

  • {
    • _index: xxx
    • _type: response
    • _id: 1
    • _score: 1
    • fields: {
      • rtext.textvalue: [
        • Jennifer,
        • Adam
          ]
          }
          },
  • {
    • _index: xxx
    • _type: response
    • _id: 1
    • _score: 1
    • fields: {
      • rtext.textvalue: [
        • John,
        • A
          ]
          }
          }

Since nested query/filter doesn't support fields how do I get just
textvalues whoose textmapid is 1 My expected output is Jennifer, John.

Any help is appreciated,
Abhishek

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Figured it out. Used the script_fields to filter the source. Any other
efficient way to do this ?

{
"script_fields": {
"textdata": {
"script": "for (int i = 0; i < _source.rtext.size();
i++){if(_source.rtext[i].textmapid == mapid){ return
_source.rtext[i].textvalue} }",
"params": {
"mapid": 1
}
}
},
"filter": {
"bool": {
"must": [
{
"nested": {
"path": "rtext",
"query": {
"bool": {
"must": [
{
"term": {
"rtext.textmapid": 1
}
}
]
}
}
}
}
]
}
}
}

On Tuesday, August 20, 2013 11:29:32 AM UTC-6, Abhishek Andhavarapu wrote:

Hi All,

My Mappings
{
"response": {
"properties": {
"rtext": {
"type": "nested",
"properties": {
"textmapid": {
"type": "integer"
},
"textvalue": {
"type": "string"
}
}
}
}
}
}

Sample data

{
"rtext" : [
{
"textmapid" : 1,
"textvalue" : "Jennifer"
},
{
"textmapid" : 2,
"textvalue" : "Adam"
}
]
},

{
"rtext" : [
{
"textmapid" : 1,
"textvalue" : "John"
},
{
"textmapid" : 2,
"textvalue" : "A"
}
]
}

Query
{
"fields": [
"rtext.textvalue"
],
"filter": {
"bool": {
"must": [
{
"nested": {
"path": "rtext",
"query": {
"bool": {
"must": [
{
"term": {
"rtext.textmapid": 1
}
}
]
}
}
}
}
]
}
}
}

My Query comes back hits: [

  • {
    • _index: xxx
    • _type: response
    • _id: 1
    • _score: 1
    • fields: {
      • rtext.textvalue: [
        • Jennifer,
        • Adam
          ]
          }
          },
  • {
    • _index: xxx
    • _type: response
    • _id: 1
    • _score: 1
    • fields: {
      • rtext.textvalue: [
        • John,
        • A
          ]
          }
          }

Since nested query/filter doesn't support fields how do I get just
textvalues whoose textmapid is 1 My expected output is Jennifer, John.

Any help is appreciated,
Abhishek

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.