elasticsearch


From MySQL query to Elastic Search DSL


This question, though seems very lengthy but I have done a thorough research & reached to a working solution already but need some improvement with my solution.
To start with,
this is a MySQL Table named content_table:
╔════╦════════════╦══════════╦═════════════╦═════════════╦═════════╦════════╗
║ id ║ title ║ type ║ genre ║ countries ║ devices ║ status ║
╠════╬════════════╬══════════╬═════════════╬═════════════╬═════════╬════════╣
║ 1 ║ without me ║ playlist ║ rap ║ US,AU,PK,NZ ║ 1,2,3,4 ║ 1 ║
║ 2 ║ Still Dre ║ playlist ║ rap hits ║ US,PK,NZ,AE ║ 1,4 ║ 1 ║
║ 3 ║ Scarface ║ movies ║ action ║ US ║ 4 ║ 1 ║
║ 4 ║ wild cats ║ video ║ documentary ║ UAE,PK,IN ║ 1,2,5 ║ 0 ║
╚════╩════════════╩══════════╩═════════════╩═════════════╩═════════╩════════╝
I have indexed this table into Elastic Search cluster using the following settings & mapping.
{
"settings":{
"analysis":{
"filter":{
"myNGramFilter":{
"type":"edgeNGram",
"min_gram":1,
"max_gram":30
}
},
"analyzer":{
"myNGramAnalyzer":{
"type":"custom",
"tokenizer":"standard",
"filter":[
"lowercase",
"myNGramFilter"
]
}
}
}
},
"mappings":{
"content":{
"properties":{
"title":{
"type":"text",
"fielddata":true,
"analyzer":"myNGramAnalyzer",
"search_analyzer":"standard"
},
"countries":{
"type":"string",
"index":"not_analyzed"
},
"devices":{
"type":"string",
"index":"not_analyzed"
},
"genre":{
"type":"text",
"fielddata":true,
"analyzer":"myNGramAnalyzer",
"search_analyzer":"standard"
}
}
}
}
}
Now I want to convert the following MySQL query into Query DSL
SELECT
*
FROM
my_table
WHERE status_srh <> 0,
AND (
countries IS NULL
OR FIND_IN_SET('US', countries_geo) > 0
)
AND FIND_IN_SET("1", device_ids)
AND (
title LIKE "Still Dre"
OR genre LIKE "rap"
)
AND (
TYPE <> 'playlist'
OR TYPE <> 'blocked content'
)
GROUP BY id,
type_srh
ORDER BY title
So far, by following the the Elastic Search Reference guide this what I have ended up in order to convert MySQL query to Query DSL :
{
"from":0,
"size":100,
"query":{
"bool":{
"must":[
{
"bool":{
"must_not":[
{
"match":{
"status":"0"
}
}
]
}
},
{
"regexp":{
"countries_geo":".*,'US',.*"
}
},
{
"regexp":{
"device_ids":".*\\\\(1).'\\\\).*"
}
},
{
"bool":{
"should":[
{
"match_phrase":{
"title":"Still"
}
},
{
"match_phrase":{
"genre":"rap"
}
}
]
}
},
{
"bool":{
"must_not":[
{
"match":{
"type":"playlist"
}
},
{
"match":{
"type":"blocked content"
}
}
]
}
}
]
}
},
"sort":{
"title":{
"order":"asc"
}
}
}
This is so far working fine and returning me a result set without errors BUT my question here is that is there a way I can improve my approach and implement the same functionality more appropriately and efficiently.Any room for improvements ? An expert opinion would be very helpful for a beginner like me. Thankyou.

Related Links

Why is my query ignoring my filter aggregation?
ElasticSearch analyzer that prioritizes order of term appearance in a search
Default elasticsearch configuration for docker container
Add alias to index from template?
Save ElasticSearch snapshot physical files in specific location
Run elasticsearch with docker
elasticsearch: How to reinitialize a node?
Elasticsearch filter on mulitple nested paths
Need to Sort the _term in elastic search aggregation result
Why search_analyzer (keyword) does not work with edgeNgram index_analyer?
Elasticsearch startup: not available immediately
Elasticsearch Partial Fields With Inner Hits
ElasticSearch issue when adding new path.data
To copy an index from one machine to another in elasticsearch
Elasticsearch 2.0: how to delete by query in Java
Erroneour match using snowball analyzer

Categories

HOME
cocoapods
macos-sierra
opencart
functional-programming
antd
kivy
adobe
semantic-web
malware
amp
joomla3.2
clickable-image
lc3
dhcp
vmware-workstation
jqxgrid
salt-cloud
error-logging
azure-machine-learning
unity-container
sipp
function-points
environment
morris.js
annotation-processing
amazon-cloudtrail
mdns
splunk-query
d3.js-v4
toad
windows2012
wampsharp
pdfminer
nsuserdefaults
django-crispy-forms
aurelia-cli
sspi
pyttsx
fiware-wirecloud
1wire
transparency
docker-ucp
axis
deployd
nonlinear-functions
lightning-workbench
amazon-elastic-beanstalk
entropy
subforms
android-sharing
popen
dblink
rcharts
java-2d
visual-studio-monaco
gcloud-node
declarative
dojo-build
fiber
static-methods
uibinder
utf-16
polymerfire
outlook.com
place
dnx50
blank-line
mixins
extend
hmisc
espresso
embeddedwebserver
relational-model
deque
gflags
thoughtworks-go
xcode6.3.1
iosched
illuminate-container
mute
mp4parser
jquery-transit
form-for
hints
significant-digits
ip-geolocation
daap
liveconnect
nsfont
radscheduler
airprint
resharper-5.1
urchin
chronic
remote-working

Resources

Encrypt Message