我想提供搜索最終用戶的類型,因爲他們去哪個更像是sqlserver。 我能夠實現ES查詢給定的SQL場景:彈性搜索Wilcard搜索或部分匹配
select * from table where name like '%pete%' and type != 'xyz and type!='abc'
但對於這個sql查詢
select * from table where name like '%peter tom%' and type != 'xyz and type!='abc'
的ES查詢不工作在我非常久遠通配符查詢彈性搜索我還需要執行一些布爾過濾查詢
{
"query": {
"filtered": {
"filter": {
"bool": {
"should": [
{
"query": {
"wildcard": {
"name":
{ "value": "*pete*" }
}
}
}
],
"must_not": [
{
"match":
{ "type": "xyz" }
}, {
"match":
{ "type": "abc" }
}
]
}
}
}
}
}
用通配符搜索上述彈性查詢工作正常,讓我所有的匹配皮特的文件,不是類型XYZ和ABC的。但是,當我嘗試執行與由2個空間seprated seprate詞語通配符那麼相同的查詢返回箱空如圖below.For例如
{
"query": {
"filtered": {
"filter": {
"bool": {
"should": [
{
"query": {
"wildcard": {
"name":
{ "value": "*peter tom*" }
}
}
}
],
"must_not": [
{
"match":
{ "type": "xyz" }
}, {
"match":
{ "type": "abc" }
}
]
}
}
}
}
}
我的映射如下:
{
"properties": {
"name": {
"type": "string"
}
"type": {
"type": "string"
}
}
}
我應該爲了使由空間
您的問題是,你不知道如何ES索引數據。看看這個https://www.elastic.co/guide/en/elasticsearch/guide/current/inverted-index.html。也期待ngGram https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-ngram-tokenizer.html –
所以問題是,當你在ES中編輯文本「hello world」時,它會變成[ 「你好,世界」]。 –
我明白如何將文檔存儲在ES中,但是ES提供了什麼以允許用戶執行sql,如搜索由空格分隔的單詞是我的問題 – andy