Nested object mapping datatypes

The dividend records of an ETF has a one-to-one relationship to the origin cf_etf index. It will be easy to embed the whole dividend records to the cf_etf index. Using a nested object datatype will make each object indexed as a separate hidden document internally. Let's add the announcement object field in the mappings of the cf_etf index and then change the announcement field from an object type to a nested object type, as follows:

{
"mappings": {
"dynamic": false,
"properties": {
"symbol": {"type": "keyword"},
"fund_name": {"type": "text"},
...
"announcement":{
"type":"nested",
"properties": {
...

In the GitHub repository of this chapter (https://github.com/PacktPublishing/Mastering-Elasticsearch-7.0/tree/master/Chapter07), there are another three files, cf_etf_dividend_nested_mappings.json, cf_etf_dividend_nested_bulk.json, and cf_etf_dividend_nested_bulk_index.shfor you to download to practice the nested object type. You can run the bash shell file to create the cf_etf_dividend_nested index and perform indexing for the 10 selected ETFs in cf_etf_dividend_nested_bulk.json. Let's issue the same search request to find the ACWF ETF with exDate on or before 2015-12-01 and the amount field greater or equal to 0.2 again. As shown in the following screenshot, the search result is correct now:

No hit is returned in the result. As you can see, you must use the nested query on the fields of the nested object type.

If you change the amount field criteria in the query to greater or equal to 0.1, then you will get a hit with one document returned, as shown in the following screenshot:

However, you do not know which nested object causes the match since all nested objects are returned because you can see the whole announcement array in the response body.

If you want to check which nested object causes the actual match, you can use the inner_hits parameter to embed those documents in the response body. You can also use options such as form, size, and sort to control the number of documents returned. Let's use the same preceding example and add an extra inner_hits parameter. In the following screenshot, you can see the response body got the inner_hits field, which only shows the actual match document with the exDate field at 2015-06-25 and amount is 0.111075:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.136.17.252