【发布时间】:2018-04-12 21:09:15
【问题描述】:
假设我们有电子商务商店数据的索引,我们想要获得 2 家商店中存在的产品列表的差异。
关于索引内容的信息:存储在每个文档中的示例数据如下所示:
{
"product_name": "sample 1",
"store_slug": "store 1",
"sales_count": 42,
"date": "2018-04-04"
}
以下是查询,这些查询分别获取了我在 2 家商店中的所有产品,
Data for store 1
curl -XGET 'localhost:9200/store/_search?pretty' -H 'Content-Type: application/json' -d'
{
"_source": ["product_name"],
"query": {
"constant_score" : {
"filter" : {
"bool" : {
"must" : [
{ "term" : { "store_slug" : "store_1"}}]}}}}}'
Data for store 2
curl -XGET 'localhost:9200/store/_search?pretty' -H 'Content-Type: application/json' -d'
{
"_source": ["product_name"],
"query": {
"constant_score" : {
"filter" : {
"bool" : {
"must" : [
{ "term" : { "store_slug" : "store_2"}}]}}}}}'
是否有可能使用弹性搜索查询来获得两种结果的差异(不使用某些脚本/其他语言)?
例如上述操作:假设“商店 1”正在销售产品 [“产品 1”、“产品 2”],而“商店 2”正在销售产品 [“产品 1”、“产品 3”],因此预期输出的差异为“商店 1”和“商店 2”的产品是“产品 2”。
【问题讨论】:
标签: elasticsearch