Bu örneğimizde elasticsearch ile SQL LIKE benzeri sorgu örnekleri yaratacağız. Daha fazla bilgi için Partial Matching sayfasını okuyun.


Not


Wildcard seçeneği filtered sorgularında kullanılamaz.


Mapping


"name": {
"type": "string",
"index": "not_analyzed" # Not a full-text search
}

Tekli LIKE


SELECT * FROM products WHERE name LIKE 'Product1*'


prefix - query


{
"query": {
"prefix": {
"name.raw": "Product1"
}
}
}

wildcard - query


{
"query": {
"wildcard": {
"name.raw": "Product1*"
}
}
}

regexp - query


{
"query": {
"regexp": {
"name.raw": "Product1.*"
}
}
}

prefix - bool


{
"query": {
"bool": {
"must": {
"prefix": {
"name.raw": "Product1"
}
}
}
}
}

{
"query": {
"bool": {
"must": [
{
"prefix": {
"name.raw": "Product1"
}
}
]
}
}
}

wildcard - bool


{
"query": {
"bool": {
"must": {
"wildcard": {
"name.raw": "Product1*"
}
}
}
}
}

{
"query": {
"bool": {
"must": [
{
"wildcard": {
"name.raw": "Product1*"
}
}
]
}
}
}

regexp - bool


{
"query": {
"bool": {
"must": {
"regexp": {
"name.raw": "Product1.*"
}
}
}
}
}

{
"query": {
"bool": {
"must": [
{
"regexp": {
"name.raw": "Product1.*"
}
}
]
}
}
}

prefix - filtered


{
"query": {
"filtered": {
"filter": {
"bool": {
"must": {
"prefix": {
"name.raw": "Product1"
}
}
}
}
}
}
}

{
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
{
"prefix": {
"name.raw": "Product1"
}
}
]
}
}
}
}
}

regexp - filtered


{
"query": {
"filtered": {
"filter": {
"bool": {
"must": {
"regexp": {
"name.raw": "Product1.*"
}
}
}
}
}
}
}

{
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
{
"regexp": {
"name.raw": "Product1.*"
}
}
]
}
}
}
}
}

Çoklu LIKE


SELECT * FROM products WHERE name LIKE 'Product1*' AND colour LIKE 'P*'


prefix - bool


{
"query": {
"bool": {
"must": [
{
"prefix": {
"name": "Product1"
}
},
{
"prefix": {
"colour": "P"
}
}
]
}
}
}

wildcard - bool


{
"query": {
"bool": {
"must": [
{
"wildcard": {
"name": "Product1*"
}
},
{
"wildcard": {
"colour": "P*"
}
}
]
}
}
}

regexp - bool


{
"query": {
"bool": {
"must": [
{
"regexp": {
"name": "Product1.*"
}
},
{
"regexp": {
"colour": "Shop7.*"
}
}
]
}
}
}

prefix - filtered


{
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
{
"prefix": {
"name": "Product1"
}
},
{
"prefix": {
"colour": "P"
}
}
]
}
}
}
}
}

regexp - filtered


{
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
{
"regexp": {
"name": "Product1.*"
}
},
{
"regexp": {
"colour": "P.*"
}
}
]
}
}
}
}
}

Çoklu LIKE ve ekstra arama terimleri


SELECT * FROM products WHERE name LIKE 'Product1*' AND colour LIKE 'P*' AND year = 2000


prefix - bool


{
"query": {
"bool": {
"must": [
{
"prefix": {
"name": "Product1"
}
},
{
"prefix": {
"colour": "P"
}
},
{
"term": {
"year": 2000
}
}
]
}
}
}

wildcard - bool


{
"query": {
"bool": {
"must": [
{
"wildcard": {
"name": "Product1*"
}
},
{
"wildcard": {
"colour": "P*"
}
},
{
"term": {
"year": 2000
}
}
]
}
}
}

regexp - bool


{
"query": {
"bool": {
"must": [
{
"regexp": {
"name": "Product1.*"
}
},
{
"regexp": {
"colour": "Shop7.*"
}
},
{
"term": {
"year": 2000
}
}
]
}
}
}

prefix - filtered


{
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
{
"prefix": {
"name": "Product1"
}
},
{
"prefix": {
"shops.name": "Shop7"
}
},
{
"term": {
"year": 2000
}
}
]
}
}
}
}
}

regexp - filtered


{
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
{
"regexp": {
"name": "Product1.*"
}
},
{
"regexp": {
"colour": "P.*"
}
},
{
"term": {
"year": 2000
}
}
]
}
}
}
}
}