[英]how to perform search in elasticsearch query?
i want to perform query like this on elastic search =>我想在弹性搜索上执行这样的查询=>
select * from orders where customerName = 'google' and Type = 'stackoverflow' and query_string can be from any index. select * 来自 customerName = 'google' 和 Type = 'stackoverflow' 且 query_string 可以来自任何索引的订单。 (ie query string can be 'google' or 'stackoverflow' or 'a' or 'b' or 'c 'or 'd' (即查询字符串可以是 'google' 或 'stackoverflow' 或 'a' 或 'b' 或 'c ' 或 'd'
table orders:
customerName type column1 column2 column3 column4
google stackoverflow a b c d
apple stackoverflow a b c d
google stackoverflow a b c d
microsoft stackoverflow a b c d
expected output:
google stackoverflow a b c d
google stackoverflow a b c d
ie row 1 and row 3即第1行和第3行
i tried using我试过用
"query": {
"bool": {
"must": {
"multi_match": {
"query": "b"
}
},
"filter": {
"terms": {
"customerName": [ "google" ],
"type": [ "stackoverflow ]
}
}
}
}
please help:)请帮忙:)
Seems like you are missing the fields(column) tag in your query.似乎您在查询中缺少 fields(column) 标记。 Assuming the schema from your relational table format, the query should be假设来自关系表格式的模式,查询应该是
{
"query": {
"bool": {
"must": {
"multi_match": {
"query": "b",
"fields": [
"column1",
"column2",
"column3",
"column4"
]
}
},
"filter": {
"terms": {
"customerName": [
"google"
],
"type": [
"stackoverflow"
]
}
}
}
}
}
Adding a working example with index data, search query, and search result添加包含索引数据、搜索查询和搜索结果的工作示例
Index Data:指数数据:
{
"customerName": "google",
"type": "stackoverflow",
"column1": "a",
"column2": "b",
"column3": "c",
"column4": "d"
}
{
"customerName": "apple",
"type": "stackoverflow",
"column1": "a",
"column2": "b",
"column3": "c",
"column4": "d"
}
{
"customerName": "google",
"type": "stackoverflow",
"column1": "a",
"column2": "b",
"column3": "c",
"column4": "d"
}
{
"customerName": "microsoft",
"type": "stackoverflow",
"column1": "a",
"column2": "b",
"column3": "c",
"column4": "d"
}
Search Query:搜索查询:
{
"query": {
"bool": {
"filter": [
{
"term": {
"customerName": "google"
}
},
{
"term": {
"type": "stackoverflow"
}
}
],
"must": {
"multi_match": {
"query": "a",
"fields": [
"customerName",
"type",
"column1",
"column2",
"column3",
"column4"
]
}
}
}
}
}
Search Result:搜索结果:
"hits": [
{
"_index": "stof_63988272",
"_type": "_doc",
"_id": "1",
"_score": 0.10536051,
"_source": {
"customerName": "google",
"type": "stackoverflow",
"column1": "a",
"column2": "b",
"column3": "c",
"column4": "d"
}
},
{
"_index": "stof_63988272",
"_type": "_doc",
"_id": "3",
"_score": 0.10536051,
"_source": {
"customerName": "google",
"type": "stackoverflow",
"column1": "a",
"column2": "b",
"column3": "c",
"column4": "d"
}
}
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.