michele
(Michele)
February 27, 2018, 2:03pm
1
I would execute a query like this (sql like):
SELECT * FROM MYINDEX WHERE SUGGEST LIKE %FOO% AND YEAR=1999
How can I do in Elastic Search?
I write a query with wild card but I don't know how to combine it with and clause that match year=1999:
{
"query": {
"wildcard" : { "name" : "*foo*" }
}
}
Can you help me?
dadoonet
(David Pilato)
February 27, 2018, 2:05pm
2
Use a bool query.
(And don't use wildcards but this is another story)
michele
(Michele)
February 27, 2018, 2:21pm
3
This is my index:
{
"mappings": {
"records" : {
"properties" : {
"suggest" : {
"type" : "completion",
"contexts": [
{
"name": "year",
"type": "category",
"path": "year"
}
]
}
}
}
}
}
dadoonet
(David Pilato)
February 27, 2018, 2:36pm
4
How can be done with this mappings?
What can be done? The query part?
michele
(Michele)
February 27, 2018, 2:58pm
5
Yes, I would do the query with LIKE %FOO% AND YEAR=1999
dadoonet
(David Pilato)
February 27, 2018, 6:39pm
6
So:
Something like:
POST _search
{
"query": {
"bool" : {
"must" : {
"wildcard" : { "name" : "%FOO%" }
},
"filter": {
"term" : { "year" : 1999 }
}
}
}
}
Some note about wildcard from doc: Wildcard Query | Elasticsearch Reference [6.2] | Elastic
Note that this query can be slow, as it needs to iterate over many terms. In order to prevent extremely slow wildcard queries, a wildcard term should not start with one of the wildcards * or ?.
system
(system)
Closed
March 27, 2018, 6:39pm
7
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.