Retrieve associated fields in a highlight query


(Chris Lees) #1

I'm trying to get a highlight query working on an indexed JSON doc (not an
attachment!).

Here's an example doc:

{
...
"file": {
"blocks": [
{
"name": "1st Block",
"fields": [
{
"id": "A",
"name": "FirstField",
"type": "String",
"desc": "This is my first field"
},
...
]
},
{
"name": "2nd Block",
"fields": [
{
"id": "C",
"name": "SecondField",
"type": "String",
"desc": "This is my second field"
},
...
]
}
]
}
}

I want to run a query which will search on the id, name or desc fields
within a blocks.fields entry, but which returns enough information for the
user to see the block.name too. Here's my current query which just
highlights the matched field correctly:

{
"query": {
"query_string": {
"query": "SecondField"
}
},
"highlight": {
"fields": {
"file.blocks.fields.id": {},
"file.blocks.fields.name": {},
"file.blocks.fields.desc": {}
}
}
}

This returns the document and a highlight section as below:

highlight: {
"file.blocks.fields.name" : [
"SecondField"
]
}

What I'd really like is to get the return something which also returns:

"file.blocks.name": "2nd Block",
"file.blocks.fields.id": "C",
"file.blocks.fields.desc": "This is my second field"

Is this possible (without doing extra processing in my application)? Or is
a highlight query the wrong thing to use here?

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/713cc3ea-006e-410e-88ee-3564435041e9%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


(system) #2