26/08/2017 - ELASTICSEARCH
In this example we're going to some elasticsearch query examples which behave like classic SQL LIKE
clause. For more information read Partial Matching.
Wildcard option cannot be used in filtered
queries.
"name": {
"type": "string",
"index": "not_analyzed" # Not a full-text search
}
SELECT * FROM products WHERE name LIKE 'Product1*'
{
"query": {
"prefix": {
"name.raw": "Product1"
}
}
}
{
"query": {
"wildcard": {
"name.raw": "Product1*"
}
}
}
{
"query": {
"regexp": {
"name.raw": "Product1.*"
}
}
}
{
"query": {
"bool": {
"must": {
"prefix": {
"name.raw": "Product1"
}
}
}
}
}
{
"query": {
"bool": {
"must": [
{
"prefix": {
"name.raw": "Product1"
}
}
]
}
}
}
{
"query": {
"bool": {
"must": {
"wildcard": {
"name.raw": "Product1*"
}
}
}
}
}
{
"query": {
"bool": {
"must": [
{
"wildcard": {
"name.raw": "Product1*"
}
}
]
}
}
}
{
"query": {
"bool": {
"must": {
"regexp": {
"name.raw": "Product1.*"
}
}
}
}
}
{
"query": {
"bool": {
"must": [
{
"regexp": {
"name.raw": "Product1.*"
}
}
]
}
}
}
{
"query": {
"filtered": {
"filter": {
"bool": {
"must": {
"prefix": {
"name.raw": "Product1"
}
}
}
}
}
}
}
{
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
{
"prefix": {
"name.raw": "Product1"
}
}
]
}
}
}
}
}
{
"query": {
"filtered": {
"filter": {
"bool": {
"must": {
"regexp": {
"name.raw": "Product1.*"
}
}
}
}
}
}
}
{
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
{
"regexp": {
"name.raw": "Product1.*"
}
}
]
}
}
}
}
}
SELECT * FROM products WHERE name LIKE 'Product1*' AND colour LIKE 'P*'
{
"query": {
"bool": {
"must": [
{
"prefix": {
"name": "Product1"
}
},
{
"prefix": {
"colour": "P"
}
}
]
}
}
}
{
"query": {
"bool": {
"must": [
{
"wildcard": {
"name": "Product1*"
}
},
{
"wildcard": {
"colour": "P*"
}
}
]
}
}
}
{
"query": {
"bool": {
"must": [
{
"regexp": {
"name": "Product1.*"
}
},
{
"regexp": {
"colour": "Shop7.*"
}
}
]
}
}
}
{
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
{
"prefix": {
"name": "Product1"
}
},
{
"prefix": {
"colour": "P"
}
}
]
}
}
}
}
}
{
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
{
"regexp": {
"name": "Product1.*"
}
},
{
"regexp": {
"colour": "P.*"
}
}
]
}
}
}
}
}
SELECT * FROM products WHERE name LIKE 'Product1*' AND colour LIKE 'P*' AND year = 2000
{
"query": {
"bool": {
"must": [
{
"prefix": {
"name": "Product1"
}
},
{
"prefix": {
"colour": "P"
}
},
{
"term": {
"year": 2000
}
}
]
}
}
}
{
"query": {
"bool": {
"must": [
{
"wildcard": {
"name": "Product1*"
}
},
{
"wildcard": {
"colour": "P*"
}
},
{
"term": {
"year": 2000
}
}
]
}
}
}
{
"query": {
"bool": {
"must": [
{
"regexp": {
"name": "Product1.*"
}
},
{
"regexp": {
"colour": "Shop7.*"
}
},
{
"term": {
"year": 2000
}
}
]
}
}
}
{
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
{
"prefix": {
"name": "Product1"
}
},
{
"prefix": {
"shops.name": "Shop7"
}
},
{
"term": {
"year": 2000
}
}
]
}
}
}
}
}
{
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
{
"regexp": {
"name": "Product1.*"
}
},
{
"regexp": {
"colour": "P.*"
}
},
{
"term": {
"year": 2000
}
}
]
}
}
}
}
}