Using OpenSearch to access indexed content

You can access indexed content through OpenSearch.

Before you begin

Fix Pack 8 and laterEnsure that you have installed and configured OpenSearch. For more information, see Installing OpenSearch.

About this task

Using OpenSearch you can publish product data in a flattened format. Data is stored in a JSON format as “Attribute Name:Value” pair. You can quickly export this data to external systems for any kind of analytics or reporting purposes.

Procedure

  1. Use the following API details to search by using a keyword, for example item2.
    URL
    http://<opensearch-host>:<port>/<index_id>/_search
    Method
    POST
    Request body
    {
        "query": {
            "bool": {
                "must": [
                    {
                        "query_string": {
                            "query": "item2",
                            "type": "cross_fields",
                            "default_operator": "AND"
                        }
                    },
                    {
                        "term": {
                            "type": "item"
                        }
                    },
                    {
                        "term": {
                            "containerName.keyword": "catalog"
                        }
                    }
                ]
            }
        },
        "size": 50,
        "from": 0,
        "aggs": {
            "Containers": {
                "filter": {
                    "term": {
                        "containerName.keyword": "catalog"
                    }
                }
            }
        }
    }
    Response body
    {
        "took": 33,
        "timed_out": false,
        "_shards": {
            "total": 1,
            "successful": 1,
            "skipped": 0,
            "failed": 0
        },
        "hits": {
            "total": {
                "value": 1,
                "relation": "eq"
            },
            "max_score": 4.698229,
            "hits": [
                {
                    "_index": "2",
                    "_id": "1027",
                    "_score": 4.698229,
                    "_source": {
                        "type": "ITEM",
                        "companyName": "mytest",
                        "containerName": "catalog",
                        "identifier": "1027",
                        "primaryKey": "item2",
                        "displayName": "item2",
                        "attributes": {
                            "cat_specs": {
                                "item_id": "item2",
                                "Name": null,
                                "Value": 120.0,
                                "ExpDate": "2023-03-11T00:00:00+0580",
                                "NewDate": null,
                                "Date2": null
                            }
                        },
                        "mappings": {
                            "hier": [
                                "cat1"
                            ]
                        },
                        "dataCompletenessPercent": [],
                        "validationErrorCount": 0,
                        "lastModifiedOn": 1678699738000,
                        "lastModifiedBy": "Admin",
                        "versionNumber": 1
                    }
                }
            ]
        },
        "aggregations": {
            "Containers": {
                "doc_count": 1
            }
        }
    }
    
  2. Optional: Use the following API details to search by using a key-value pair, for example item_id and item2.
    URL
    http://<opensearch-host>:<port>/<index_id>/_search
    Method
    POST
    Request body
    {
        "query": {
            "bool": {
                "must": [
                    {
                        "query_string": {
                            "fields": [
                                "attributes.cat_specs.item_id"
                            ],
                            "query": "item2",
                            "default_operator": "AND"
                        }
                    },
                    {
                        "term": {
                            "type": "item"
                        }
                    },
                    {
                        "term": {
                            "containerName.keyword": "catalog"
                        }
                    }
                ]
            }
        },
        "highlight": {
            "fields": {
                "attributes.cat_specs/item_id": {}
            }
        },
        "size": 50,
        "from": 0,
        "aggs": {
            "Containers": {
                "filter": {
                    "term": {
                        "containerName.keyword": "catalog"
                    }
                }
            }
        }
    }
    Where,
    • cat_specs is the spec name,
    • item_id is the attribute name,
    • catalog is the containerName.
    Response body
    {
        "took": 11,
        "timed_out": false,
        "_shards": {
            "total": 1,
            "successful": 1,
            "skipped": 0,
            "failed": 0
        },
        "hits": {
            "total": {
                "value": 1,
                "relation": "eq"
            },
            "max_score": 4.02548,
            "hits": [
                {
                    "_index": "2",
                    "_id": "1027",
                    "_score": 4.02548,
                    "_source": {
                        "type": "ITEM",
                        "companyName": "mytest",
                        "containerName": "catalog",
                        "identifier": "1027",
                        "primaryKey": "item2",
                        "displayName": "item2",
                        "attributes": {
                            "cat_specs": {
                                "item_id": "item2",
                                "Name": null,
                                "Value": 120.0,
                                "ExpDate": "2023-03-11T00:00:00+0580",
                                "NewDate": null,
                                "Date2": null
                            }
                        },
                        "mappings": {
                            "hier": [
                                "cat1"
                            ]
                        },
                        "dataCompletenessPercent": [],
                        "validationErrorCount": 0,
                        "lastModifiedOn": 1678699738000,
                        "lastModifiedBy": "Admin",
                        "versionNumber": 1
                    }
                }
            ]
        },
        "aggregations": {
            "Containers": {
                "doc_count": 1
            }
        }
    }
    

Example


JSON file format
{
    "took": 21,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 1,
            "relation": "eq"
        },
        "max_score": 10.309448,
        "hits": [
            {
                "_index": "2",
                "_id": "9980",
                "_score": 10.309448,
                "_source": {
                    "type": "ITEM",
                    "companyName": "demo",
                    "containerName": "Product Offerings",
                    "identifier": "9980",
                    "primaryKey": "3912",
                    "displayName": "Nokia 7205",
                    "attributes": {
                        "Product Specification": {
                            "Product ID": "3912",
                            "Model ID": "Nokia 7205",
                            "Model Name": "Intrigue",
                            "Vendor": "Vendor Lookup»Nokia»",
                            "Product Type": "Mobile",
                            "Dimensions": null,
                            "Colors": [],
                            "Images": {
                                "Web Image": "nokia7205-1356314092-0.jpg",
                                "Image URL": "http://hdimages-raw.s3.amazonaws.com/nokia7205-1356314092-0.jpg"
                            },
                            "Features": [
                                "500 entries",
                                "Caller groups",
                                "Multiple numbers per contact",
                                "Picture ID",
                                "Ring ID",
                                "Calendar",
                                "Alarm",
                                "To-Do",
                                "Calculator",
                                "World clock",
                                "Stopwatch",
                                "Notes",
                                "SMS",
                                "MMS",
                                "Predictive text input",
                                "Instant Messaging",
                                "Games",
                                "Advanced Audio Distribution (A2DP)",
                                "Basic Imaging (BIP)",
                                "Basic Printing (BPP)",
                                "Dial-up networking (DUN)",
                                "File Transfer (FTP)",
                                "Generic Access (GAP)",
                                "Generic Audio\/Video Distribution (GAVDP)",
                                "Handsfree (HFP)",
                                "Headset (HSP)",
                                "Object Push (OPP)",
                                "Serial Port (SPP)",
                                "Polyphonic ringtones",
                                "Vibration",
                                "Phone profiles",
                                "Speakerphone",
                                "Voice dialing (Speaker independent)",
                                "Voice commands (Speaker independent)",
                                "Voice recording",
                                "TTY\/TDD"
                            ],
                            "Descriptions": {},
                            "Display Image": "nokia7205-1356314092-0.jpg",
                            "Display Image Description": null,
                            "Digital Assets": [],
                            "Related": [],
                            "Completeness_Core": null,
                            "Completeness_Amazon": null,
                            "Completeness_eBay": null,
                            "Completeness_Adobe": null,
                            "Completeness_Google": null,
                            "Completeness_Magento": null
                        },
                        "Publication Secondary Spec": {
                            "Publication Group": []
                        },
                        "Region": {
                            "Region": []
                        },
                        "Core": {
                            "0001_INTERNAL_PRODUCT_CODE": null,
                            "0590_CODE_INFOS": {},
                            "1039_SAP_AFFILIATE": {},
                            "0794_CONSUMER_UNIT_INFOS": {},
                            "0797_TRADE_UNIT": {}
                        },
                        "Mobile Specifications": {
                            "General": {
                                "App": null,
                                "App Version": null,
                                "App Category": "microSD,microSDHC",
                                "CPU": null,
                                "Connectors": "MicroUSB,2.5mm Audio",
                                "Battery": "Li-Ion 860 mAh",
                                "Aliases": null,
                                "Platform": null,
                                "Platform Version": null,
                                "Platform Version Max": null,
                                "Benchmark Max": "0",
                                "Benchmark Min": null,
                                "Memory Internal": "150MB",
                                "Memory Slot": "MP3,AAC,AAC+,WMA",
                                "Network": "CDMA800,CDMA1900,Bluetooth 2.0",
                                "Browser": null,
                                "Browser Version": null,
                                "Language": "240"
                            },
                            "Display": {
                                "Size": "2.2",
                                "CSS Screen Sizes": "240x320",
                                "Virtual": "0",
                                "EUSAR": null,
                                "Type": "TFT",
                                "Pixel Ratio": "1",
                                "PPI": "182",
                                "X Ratio": "2",
                                "Y Ratio": "0",
                                "Display Colors": "262K",
                                "Other": "Second External"
                            },
                            "Media": {
                                "Front Camera": "2MP,1600x1200",
                                "Secondary Camera": null,
                                "Video Capture": "Yes",
                                "Video Playback": null,
                                "Audio": "Digital zoom,LED Flash",
                                "Other": "Internal"
                            },
                            "Design": {
                                "Form Factor": "Clamshell",
                                "Keyboard": "Numeric",
                                "Weight": "90",
                                "Side Keys": "Volume",
                                "Dimensions": "90 x 47 x 14",
                                "Antenna": null,
                                "Softkeys": "320"
                            }
                        },
                        "Approval Secondary Spec": {
                            "Approval Details": []
                        }
                    },
                    "mappings": {
                        "Primary Hierarchy": [
                            "Nokia"
                        ]
                    },
                    "dataCompletenessPercent": [
                        {
                            "channel": "Core",
                            "completeness": null
                        },
                        {
                            "channel": "Amazon",
                            "completeness": null
                        },
                        {
                            "channel": "eBay",
                            "completeness": null
                        },
                        {
                            "channel": "Adobe",
                            "completeness": null
                        },
                        {
                            "channel": "Google",
                            "completeness": null
                        },
                        {
                            "channel": "Magento",
                            "completeness": null
                        }
                    ],
                    "validationErrorCount": 0,
                    "lastModifiedOn": 1619539957000,
                    "lastModifiedBy": null,
                    "versionNumber": -1
                }
            }
        ]
    },
    "aggregations": {
        "Containers": {
            "doc_count": 1
        }
    }
}