相关搜索条件,如使用elasticsearch的pinterest

时间:2016-03-15 12:27:47

标签: search elasticsearch full-text-search pinterest elasticsearch-plugin

我需要实现类似于Pinterest搜索词的功能。例如,如果我搜索“旅行”,我应该获得相关搜索字词,例如“旅行提示”,“旅游目的地”, “海滩旅行”等等。关于此的结果可以参考https://in.pinterest.com/search/pins/?q=travel&rs=typed&0=travel|typed

我正在使用弹性搜索。需要知道我应该使用的弹性搜索的确切概念/逻辑/算法。

到目前为止我所做的是将类别存储在如下文档

POST /category/search/1
{ "category_id" : 1, "term" : "travel" }

POST /category/search/2
{ "category_id" : 2, "term" : "travel beach" }

POST /category/search/3
{ "category_id" : 3, "term" : "travel in car" }

POST /category/search/4
{ "category_id" : 4, "term" : "weekend travel" }

POST /category/search/5
{ "category_id" : 5, "term" : "travel bucket list" }

使用以下查询进行搜索

GET /category/search/_search
{
  "query" : {
    "match_phrase" : {
        "term" : "travel"
    }
  }
}

我得到的结果

{
  "took": 686,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 5,
    "max_score": 0.37158427,
    "hits": [
      {
    "_index": "category",
    "_type": "search",
    "_id": "2",
    "_score": 0.37158427,
    "_source": {
      "category_id": 1,
      "term": "travel beach"
    }
      },
      {
    "_index": "category",
    "_type": "search",
    "_id": "4",
    "_score": 0.37158427,
    "_source": {
      "category_id": 1,
      "term": "weekend travel"
    }
      },
      {
    "_index": "category",
    "_type": "search",
    "_id": "1",
    "_score": 0.30685282,
    "_source": {
      "category_id": 1,
      "term": "travel"
    }
      },
      {
    "_index": "category",
    "_type": "search",
    "_id": "5",
    "_score": 0.15342641,
    "_source": {
      "category_id": 1,
      "term": "travel bucket list"
    }
      },
      {
    "_index": "category",
    "_type": "search",
    "_id": "3",
    "_score": 0.15342641,
    "_source": {
      "category_id": 1,
      "term": "travel in car"
    }
      }
    ]
  }
}

我期待“海滩”,“周末”等结果。

0 个答案:

没有答案