[英]how to perform search in elasticsearch query?
我想在彈性搜索上執行這樣的查詢=>
select * 來自 customerName = 'google' 和 Type = 'stackoverflow' 且 query_string 可以來自任何索引的訂單。 (即查詢字符串可以是 '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
即第1行和第3行
我試過用
"query": {
"bool": {
"must": {
"multi_match": {
"query": "b"
}
},
"filter": {
"terms": {
"customerName": [ "google" ],
"type": [ "stackoverflow ]
}
}
}
}
請幫忙:)
似乎您在查詢中缺少 fields(column) 標記。 假設來自關系表格式的模式,查詢應該是
{
"query": {
"bool": {
"must": {
"multi_match": {
"query": "b",
"fields": [
"column1",
"column2",
"column3",
"column4"
]
}
},
"filter": {
"terms": {
"customerName": [
"google"
],
"type": [
"stackoverflow"
]
}
}
}
}
}
添加包含索引數據、搜索查詢和搜索結果的工作示例
指數數據:
{
"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"
}
搜索查詢:
{
"query": {
"bool": {
"filter": [
{
"term": {
"customerName": "google"
}
},
{
"term": {
"type": "stackoverflow"
}
}
],
"must": {
"multi_match": {
"query": "a",
"fields": [
"customerName",
"type",
"column1",
"column2",
"column3",
"column4"
]
}
}
}
}
}
搜索結果:
"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.