elasticsearch


Constructing ElasticSearch Query with nested Should operator


I am struggling to create a simple ElasticSearch Query.
This is what i want to achieve in simple SQL
SELECT * FROM products WHERE (title='LG' OR title='Nokia') AND (brand='Samsung' OR title='iPhone')
This is my Elasticsearch query:
"query": {
"bool": {
"must": [
{
"bool": {
"should": [
{
"match": {
"product-name": "Samsung"
}
},
{
"match": {
"product-name": "Nokia"
}
}
],
"minimum_should_match": 1
}
}
]
}
}
This returns me the first line of the Psuedo SQL WHERE (title='LG' OR title='Nokia')
But how can i construct the AND (brand='Samsung' OR title='iPhone')
Following query should get the job done. You need to add one more block in must clause.
{
"query": {
"bool": {
"must": [
{
"bool": {
"should": [
{
"match": {
"product-name": "LG"
}
},
{
"match": {
"product-name": "Nokia"
}
}
],
"minimum_should_match": 1
}
} ,
{
"bool": {
"should": [
{
"match": {
"brand": "Samsung"
}
},
{
"match": {
"title": "iPhone"
}
}
],
"minimum_should_match": 1
}
}
]
}
}
}
Hope this helps

Related Links

Logstash Grok Modifying and overwriting #timestamp
how to restore elasticsearch.yml config file to original?
Index a graph with ElasticSearch
ElasticSearch query not returning expected results
Fluentd High Availability Custom Index
How do I add an attribute to an Elasticsearch node for the purpose of Shard Allocation Filtering?
Configure ElasticSearch attachment mapper to use OCR plugin
ElasticSearch: How to search for a value in any field, across all types, in one or more indices?
Phrase suggestor - which index and query to act upon
Adding additional fields to ElasticSearch terms aggregation
ElasticSearch multi_match if field exists apply filter otherwise dont worry about it?
ElasticSearch Date Histogram Interval
Kibana 4 index patterns time-field
elasticsearch: Did I lose data when two of my three nodes went down?
ElasticSearch automatic typing
how to copy ElasticSearch field to another field

Categories

HOME
jboss
rust
spring-data
mpdf
yii
qc
softlayer
apk
celery
cypher
flurry
jint
lda
sap-fiori
spring-amqp
stimulsoft
uima
exe
rpmbuild
scheduled-tasks
parceler
jest
yii2-basic-app
acl
sipp
jstree
hevc
php-5.3
sendmessage
intune
location-services
cloveretl
polyml
cups
pdfnet
bluemixtools
stat
robust
spooler
httphandler
vesta
jshint
tinyioc
renderman
solr-query-syntax
zend-server
maatwebsite-excel
yargs
svnserve
callouts
bbc-micro
noclassdeffounderror
mercurial-extension
currency-exchange-rates
ioexception
flask-security
teensy
textpattern
html.actionlink
mousehover
fanotify
cfwheels
espresso
gql
roxygen2
dynamics-ax-2012-r2
textscan
com0com
erlog
mgwt
mutators
findersync
maven-shade-plugin
tabris
object-code
squeezebox
jini
fileshare
typesafe-stack
progress-db
ldif
jquery-lazyload
oscilloscope
asp.net-mvc-3-areas
examine
django-filebrowser
idispatch
stretch
wndproc
server-name
prototypal-inheritance
nsfont
kolite
qt-mobility
3des
qcar-sdk
active-record-query
icicles
ixmldomdocument
powergui
icon-language
levels
error-detection

Resources

Encrypt Message