Discover query with geolocation

Hi,

FYI, I'm just a newbie with ES, but so... let's start :slight_smile:

I currently have a "discovery query", imagine that I have "stores" and each store has "products".
Noticed that each store is geolocalized. So, the idea is to help to discover products around.

My current query is not very advanced, but already score based on:

  • Distance between the current location and the store location
  • The doc last update time
  • a set of "preferred-keywords" associated with the current user

For example, if I like "shoes", I should "mainly" see shoes around but also some other stuff.
Of course, I have a set of "preferred-keywords", each one with another weight!

By example, imagine I have the following "preferred-keywords":

  • shoes: 0.5
  • food : 0.2
  • phone : 0.1
  • ...

The problem now is that I got

  • all the shoes from store A, then store B (A closer than B)
  • all the food from store C, then store D (C closer then D)
  • etc...

I know that order is defined by the score, it makes sense, but such result is not pleasant and does not really help to discover!

So, my question is how can I mix all theses 'doc' to avoid such effects (But keeping the score very important).

Is there some tips & tricks, for example, ideas, etc?

PS: I imagine that it should be possible, if I like "blue classic shoes" on Pinterest, they present my related stuffs from all around, the same for Instagram etc...! But how :stuck_out_tongue:

Thanks for your guidance

What's unpleasant about it? Can you define mix? Have you tried boosting field you care more or boosting query?

Can you share your query?

Thanks for your answer,

What is unpleasant is that I see first all the results from "store A", then all from "store B".
So, there is a change that "store B" will never been seen (because store A has a lot of doc)

You can loo at : socloze.com ... you will see all the furnitures, then all the camera. Here I only have 2 stores, imagine if I have 200 stores around.

So, I'm looking for a way to mix more, on not focussing on a specific store first !
Addind some "kind of randomness" by example... or using the "store-id" to not display more than 2/3 results each 20 items (except when there is not enough content), etc...

Here is my query

{

    "output": "./output_posts.html|json",

    "params": {

        "preferedKeywords": "reflex clock",

        "preferedKeywords2": "reflex clock",

        "preferedKeywords3": "reflex clock",

        "distance_pivot" : "50km",

        "time_pivot" : "42d",

    }

}

POST /posts_index/_search(name="dslquery_posts")

{

    "track_total_hits": true,

    "from":0,

    "size":1000,

    "_source": [

        "id",

        "tags",

        "taxonomies",

        "storesNames",

        "geoLocations",

        "storesIds",

        "imageUri",

        "imageTags"

    ],

    

    "query": {

        "function_score": {

            "query": {

                "bool": {

                    "should": [

                        {

                            "distance_feature": {

                                "field": "geoLocations",

                                "pivot": "{{distance_pivot}}",

                                "origin": [

                                    -71.3,

                                    41.15

                                ]

                            }

                        },

                        {

                            "distance_feature": {

                                "field": "updateTime",

                                "pivot": "{{time_pivot}}",

                                "origin": "now"

                            }

                        },

                        {

                            "query_string": {

                                "fields": [

                                    "tags^3",

                                    "taxonomies^5"

                                ],

                                "query": "{{preferedKeywords}}",

                                "fuzziness": "auto"

                            }

                        },

                        {

                            "nested": {

                                "path": "imageTags",

                                "score_mode": "sum",

                                "query": {

                                    "function_score": {

                                        "query": {

                                            "query_string": {

                                                "fields": [

                                                    "imageTags.tag^5"

                                                ],

                                                "query": "{{preferedKeywords2}}",

                                                "fuzziness": "auto",

                                                "default_operator": "AND"

                                            }

                                        },

                                        "field_value_factor": {

                                            "field": "imageTags.score",

                                            "factor": 1,

                                            "missing": 0

                                        }

                                    }

                                }

                            }

                        },

                        {

                            "nested": {

                                "path": "imageTags",

                                "score_mode": "sum",

                                "query": {

                                    "function_score": {

                                        "query": {

                                            "query_string": {

                                                "fields": [

                                                    "imageTags.tag^2"

                                                ],

                                                "query": "{{preferedKeywords3}}",

                                                "fuzziness": "auto",

                                                "default_operator": "OR"

                                            }

                                        },

                                        "field_value_factor": {

                                            "field": "imageTags.score",

                                            "factor": 1,

                                            "missing": 0

                                        }

                                    }

                                }

                            }

                        }

            

                    ]

                }

            },

            "functions": [

                {

                    "script_score": {

                        "script": {

                            "source": "Math.sqrt(doc['commentsCount'].value)"

                        }

                    }

                },

                {

                    "script_score": {

                        "script": {

                            "source": "Math.log(2 + doc['likesCount'].value)"

                        }

                    }

                },

                {

                    "script_score": {

                        "script": {

                            "source": "Math.log(2 + doc['viewsCount'].value)"

                        }

                    }

                }

            ],

            "score_mode": "avg"

        }

    }

}

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