【发布时间】:2021-07-01 07:32:49
【问题描述】:
我正在尝试对亚马逊产品数据执行基于内容的推荐,数据存储在名为“amazon_products”的 ElasticSearch 索引中。
我通过https://elasticsearch-dsl.readthedocs.io/en/latest/search_dsl.html#more-like-this-query 在 ES 的 python 客户端中使用 MLT 查询,并在尝试时没有得到任何响应。
以下是我的代码:
os.environ['PYSPARK_SUBMIT_ARGS'] = '--packages org.elasticsearch:elasticsearch-hadoop:7.7.1 pyspark-shell'
from elasticsearch import Elasticsearch
es = Elasticsearch()
from elasticsearch_dsl import Search
from elasticsearch_dsl.query import MoreLikeThis
dsl_search = Search(index='amazon_products').using(es)
input_product = 'Ginger'
content_dsl = dsl_search.query(MoreLikeThis(like= input_product, fields=['brand']))
response = content_dsl.execute()
print(response)
for hit in response:
print(hit)
即使在“品牌”字段下有“Ginger”,响应也只是空的 {}。为什么会这样?
在创建索引amazon_products 并将数据映射到其中之后,我可以像这样执行普通的搜索查询:
es.search(index="amazon_products", q="main_category:Refrigerators", size=3)
这似乎工作正常并给出了正确的结果。
但是,我不明白为什么 MLT 不能处理我的数据。有人可以帮我解决这个问题吗?我该怎么办?
我还应该如何在 Python 中执行 MLT 查询?
【问题讨论】:
标签: python elasticsearch pyspark morelikethis