问题描述
我的数据从平面文件进入logstash我试图查询弹性搜索。
OrderNumber ProductName
order1 Chicken
order2香蕉
order3 Chicken
order1黄瓜
订单2鸡
订单3苹果
订单1面粉
订单2米
订单3坚果
如上所述,我有一个鸡< 的产品名称,发生在不同的订单号。
OrderNumber ProductName
order1 Chicken
order3 Chicken
order2 Chicken
这是我想要实现的:
步骤1:查找包含鸡的所有订单号
OrderNu mber ProductName
order1 Chicken
order3 Chicken
order2 Chicken
步骤2:如果上面的订单有鸡,它给我所有其他也被购买的产品
结果:
OrderNumber ProductName
order1黄瓜
order2香蕉
order3苹果
order1面粉
order2 Rice
order3坚果
这是我迄今为止尝试过的 Step1
查询
{
query:{
match:{
ProductName:Chicken
}
}
}
结果
hits:{
total:3,
max_score:11.378191,
hits:[{
_index:hello,
_type:logs,
_id:AVmxaChupyZuCjD89xPX,
_score:11.378191,
_source:{
message:order1\Chicken\r,
path:C:\\utils\\\Elk\\loglog \\\bin\\product.log,
OrderNumber:order1,
ProductName:Chicken\r
}},{
_index:hello,
_type:logs,
_id:AVmxaChupyZuCjD89xPX,
_score:11.378191,
_source :{
message:order3\Chicken\r,
path:C:\\utils\\Elk\\logstash\\\\ bin \\product.log,
OrderNumber:order3,
ProductName:Chicken\r
}
},{
_index:hello,
_type:logs,
_id:AVmxaChupyZuCjD89xPX,
_sco re:11.378191,
_source:{
message:order2\Chicken\r,
path:C:\\utils\ \Elk\\logstash\\bin\\product.log,
OrderNumber:order2,
ProductName:Chicken\r
}
我非常困惑,如何完成步骤2 ,因为我非常新的Elasticsearch,请帮助?
谢谢
要搜索具有 Chicken
和 Chicken
之外的产品名称的文档,您可以使用以下查询:
{
查询:{
和:[
{
条款:{
OrderNumber:[order1,order2,order3]
}
},
{
not:{
term:{
Pr oductName:鸡
}
}
}
]
}
}
I am trying to query elasticsearch in order to find out what products were bought with a certain product.
My data going into logstash from a flat file.
OrderNumber ProductName
order1 Chicken
order2 Banana
order3 Chicken
order1 Cucumber
order2 Chicken
order3 Apples
order1 Flour
order2 Rice
order3 Nuts
As you can see above i have an Product Name of Chicken which occurs in different Order Numbers.
OrderNumber ProductName
order1 Chicken
order3 Chicken
order2 Chicken
This is what i would like to achieve :
Step 1 : Lookup all order Numbers that contain chicken
OrderNumber ProductName
order1 Chicken
order3 Chicken
order2 Chicken
Step 2 : if the above orders have chicken in it give me all the other products that was also purchased with it
Result :
OrderNumber ProductName
order1 Cucumber
order2 Banana
order3 Apples
order1 Flour
order2 Rice
order3 Nuts
This is what i have tried so far for Step1 :
Query
{
"query" : {
"match" : {
"ProductName" : "Chicken"
}
}
}
Result
"hits" : {
"total" : 3,
"max_score" : 11.378191,
"hits" : [ {
"_index" : "hello",
"_type" : "logs",
"_id" : "AVmxaChupyZuCjD89xPX",
"_score" : 11.378191,
"_source" : {
"message" : "order1\Chicken\r",
"path" : "C:\\utils\\Elk\\logstash\\bin\\product.log",
"OrderNumber" : "order1",
"ProductName" : "Chicken\r"
}}, {
"_index" : "hello",
"_type" : "logs",
"_id" : "AVmxaChupyZuCjD89xPX",
"_score" : 11.378191,
"_source" : {
"message" : "order3\Chicken\r",
"path" : "C:\\utils\\Elk\\logstash\\bin\\product.log",
"OrderNumber" : "order3",
"ProductName" : "Chicken\r"
}
}, {
"_index" : "hello",
"_type" : "logs",
"_id" : "AVmxaChupyZuCjD89xPX",
"_score" : 11.378191,
"_source" : {
"message" : "order2\Chicken\r",
"path" : "C:\\utils\\Elk\\logstash\\bin\\product.log",
"OrderNumber" : "order2",
"ProductName" : "Chicken\r"
}
I'm very confused as to how to go about completing step 2 as I am very new to Elasticsearch, please help ?
Thanks
To search for documents that have order numbers found for Chicken
and product names other than Chicken
, you can use the following query:
{
"query" : {
"and" : [
{
"terms" : {
"OrderNumber" : ["order1", "order2", "order3"]
}
},
{
"not" : {
"term" : {
"ProductName" : "Chicken"
}
}
}
]
}
}
这篇关于查询弹性搜索JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!