Sample data and testing

This section contains sample data and its testing result.

Create some orders for testing.

Persona A	iphone		powerbank	headphone
Persona A	powerbank	headphone
Persona A	ipad		headphone
Persona B	ipad		headphone
Persona C	powerbank	headphone	sdcard
Persona D	lgphone		sdcard		powerbank

Different products have different product recomendation .

powerbank -> headphone and sdcard
headphone -> ipad and powerbank
Ipad      -> headphone
iphone    -> nothing
monitor   -> nothing
sdcard    -> powerbank

The Postman can be used to send a test request.
Send POST request to http://localhost:9200/purchasehistorydocument.invariant/_search
Set the JSON body to request:

{
    "aggs": {
        "product_recommendations": {
            "significant_terms": {
                "exclude": [
                    "powerbankvar"
                ],
                "field": "products",
                "min_doc_count": 2
            }
        }
    },
    "query": {
        "match": {
            "products": "powerbankvar"
        }
    }
}

Sample response

{
    "took": 2,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 3,
            "relation": "eq"
        },
        "max_score": 0.7203411,
        "hits": [
            {
                "_index": "purchasehistorydocument.invariant",
                "_type": "_doc",
                "_id": "LSC100003",
                "_score": 0.7203411,
                "_source": {
                    "user": "daa65f00-06e5-4177-a7c0-011fe68d1620",
                    "products": [
                        "iphonevar",
                        "ipadvar",
                        "headphonevar",
                        "powerbankvar"
                    ]
                }
            },
            {
                "_index": "purchasehistorydocument.invariant",
                "_type": "_doc",
                "_id": "LSC100005",
                "_score": 0.7203411,
                "_source": {
                    "user": "aa9981dd-30bd-4a85-a41c-12dceceb9bf0",
                    "products": [
                        "powerbankvar",
                        "sdcardvar",
                        "headphonevar"
                    ]
                }
            },
            {
                "_index": "purchasehistorydocument.invariant",
                "_type": "_doc",
                "_id": "LSC100006",
                "_score": 0.7203411,
                "_source": {
                    "user": "2be1bd62-89cf-42b8-8bba-a847f9f3998e",
                    "products": [
                        "sdcardvar",
                        "lgphonevar",
                        "powerbankvar"
                    ]
                }
            }
        ]
    },
    "aggregations": {
        "product_recommendations": {
            "doc_count": 3,
            "bg_count": 5,
            "buckets": [
                {
                    "key": "sdcardvar",
                    "doc_count": 2,
                    "score": 0.4444444444444443,
                    "bg_count": 2
                },
                {
                    "key": "headphonevar",
                    "doc_count": 2,
                    "score": 0.07407407407407406,
                    "bg_count": 3
                }
            ]
        }
    }
}