How to get related field from highlighting with nested fields in the document

I search for the contents of a book, which is in an array of books and the array is part of a bookstore. I have the highlighting working, however it does not tell me which book was hit. How do I get the book id?

index:


{
  "mappings": {
    "_doc": {
      "properties": {

        "books": {

          "properties": {

            "book": {
              "properties": {
                
                "book_content": {
                  "type": "long"
                },
               }
            },
           
            "book_content_type": {
              "type": "text",
              "fields": {
                "keyword": {
                  "type": "keyword",
                  "ignore_above": 256
                }
              }
            },
            "book_id": {
              "type": "long"
            },
            "book_name": {
              "type": "text",
              "fields": {
                "keyword": {
                  "type": "keyword",
                  "ignore_above": 256
                }
              }
            },
            
          }
        },
        "store_name": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        },
        "store_id": {
          "type": "long"
        },
        
           
      }
    }
  }
}

Query:


GET book_search/_search
{
	"from":0,

"highlight":
	{"fields":{"*":
		{"post_tags":["</span>"],
		  "pre_tags":["<span class='hit' style='background-color:yellow'>"]}}},

"query":{"query_string":{"analyze_wildcard":true,"default_operator":"or","fields":["*"],"query":"*blue*"}},"size":10,"sort":[{"_score":{"order":"desc"}}],"track_scores":true}

search results: says books.book_content as the highlight, but how do i get the book id?


...
}
          ],
          "store_name" : "Jeff's Bookstore",
          "store_id" : "501",

 },
        "highlight" : {
          "books.book_content" : [

		the <span class='hit' style='background-color:yellow'>blue</span> car,  
          ]

...

Thanks for the help.

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