我知道在elasticsearch doc中说过,不建议做某种东西,但我想在不同类型之间做相当的sql连接。
我正在使用嵌套c#库,它允许我做一些动态构建的请求以及可以使用先前请求结果的连续请求。
我看到了模拟子查询的解决方案: 在第一个类型中发出第一个请求,其中包含一个用作连接列的id列表
使用我在过滤器查询中更早获得的id列表,在第二种类型中发出第二个请求。这允许我使sql“in”等效
也许你会看到更好的解决方案。
我快速写了一个例子:<a OnClick="document.getElementById('#IdOfTab').click()">Link</a>
使用nest我可以从第一个结果构建一些绑定请求:
POST _bulk
{"index":{"_index":"test_index","_type":"person"}}
{"name":"Michael", "birthdate":"1989-10-1", "sport":"Baseball", "id_person" : 1}
{"index":{"_index":"test_index","_type":"person"}}
{"name":"Bob", "birthdate":"1989-11-2", "sport":"Basketball","id_person" : 2}
{"index":{"_index":"test_index","_type":"person"}}
{"name":"Jim", "birthdate":"1988-10-3", "sport":"Basketball", "id_person" : 3}
{"index":{"_index":"test_index","_type":"person"}}
{"name":"Steve", "birthdate":"1987-10-3", "sport":"Basketball", "id_person" : 4}
POST _bulk
{"index":{"_index":"test_index","_type":"bill"}}
{"type_bill" : "expenses", "id_person" : 1, "date_bill" : "2012-10-1"}
{"index":{"_index":"test_index","_type":"bill"}}
{"type_bill" : "income", "id_person" : 1, "date_bill" : "2014-10-8"}
{"index":{"_index":"test_index","_type":"bill"}}
{"type_bill" : "expenses", "id_person" : 1, "date_bill" : "2010-04-9"}
{"index":{"_index":"test_index","_type":"bill"}}
{"type_bill" : "income", "id_person" : 2, "date_bill" : "2015-12-5"}
{"index":{"_index":"test_index","_type":"bill"}}
{"type_bill" : "expenses", "id_person" : 2, "date_bill" : "2015-12-5"}
{"index":{"_index":"test_index","_type":"bill"}}
{"type_bill" : "incomes", "id_person" : 2, "date_bill" : "2015-12-5"}
{"index":{"_index":"test_index","_type":"bill"}}
{"type_bill" : "income", "id_person" : 2, "date_bill" : "2015-12-10"}
{"index":{"_index":"test_index","_type":"bill"}}
{"type_bill" : "expenses", "id_person" : 3, "date_bill" : "2016-06-5"}
{"index":{"_index":"test_index","_type":"bill"}}
{"type_bill" : "income", "id_person" : 4, "date_bill" : "2015-08-8"}
POST _bulk
{"index":{"_index":"test_index","_type":"interview"}}
{"date_match" : "2016-01-1", "id_person" : 1, "topic" : "sport", "communication_way" : "radio"}
{"index":{"_index":"test_index","_type":"interview"}}
{"date_match" : "2016-02-1", "id_person" : 1, "topic" : "sport","communication_way" : "radio"}
{"index":{"_index":"test_index","_type":"interview"}}
{"date_match" : "2016-06-1", "id_person" : 2, "topic" : "women","communication_way" : "tv"}
{"index":{"_index":"test_index","_type":"interview"}}
{"date_match" : "2016-10-1", "id_person" : 3, "topic" : "myself", "communication_way" : "tv"}
{"index":{"_index":"test_index","_type":"interview"}}
{"date_match" : "2016-01-5", "id_person" : 3, "topic" : "sport", "communication_way" : "press"}
{"index":{"_index":"test_index","_type":"interview"}}
{"date_match" : "2016-01-1", "id_person" : 4, "topic" : "women" , "communication_way" : "press"}
GET test_index/person/_search
{
"query" : {
"match" : { "sport" : "Basketball" }
},
"_source": "id_person"
}
我在第一个请求的过滤查询中使用第一个请求的结果(ids 2 3和4)
GET test_index/person/_search
{
"query" : {
"match" : { "sport" : "Basketball" }
},
"_source": "id_person"
}
您是否有其他想法会使用其他机制或弹性搜索查询?