elasticsearch


Elasticsearch filter on mulitple nested paths


I have an ES index with nested data which is mapped like this
"mappings": {
"voertuig": {
"properties": {
"vestiging": {
"properties": {
"name_dtc": {
"type": "string",
"fields": {
"raw": {
"index": "not_analyzed",
"type": "string"
}
}
},
},
"type": "nested"
},
"accessoires": {
"properties": {
"name": {
"type": "string",
"fields": {
"raw": {
"index": "not_analyzed",
"type": "string"
}
}
}
},
"type": "nested"
}
}
}
}
I would like to create a query that filters on both (raw) values. I am able to create a filter that filters on one of these values, like this:
{
"body": {
"post_filter": {
"nested": {
"filter": {
"bool": {
"must": [
{
"term": {
"vestiging.name_dtc.raw": "Location X"
}
}
]
}
},
"path": "vestiging"
}
},
"query": {
"match_all": { }
}
},
"index": "ocm",
"type": "voertuig"
}
However, what I need is something like this:
{
"body": {
"post_filter": {
"nested": [
{
"filter": {
"bool": {
"must": [
{
"term": {
"accessoires.name.raw": "Climate Control"
}
}
]
}
},
"path": "opties"
},
{
"filter": {
"bool": {
"must": [
{
"term": {
"vestiging.name_dtc.raw": "Location X"
}
}
]
}
},
"path": "vestiging"
}
]
},
"query": {
"filtered": {
"filter": {
"term": {
"key": "33e75ff09dd6"
}
},
"query": []
}
}
},
"index": "ocm",
"type": "voertuig"
}
The first query works the second one raises an error:
nested: QueryParsingException[[ocm] [nested] filter does not support [null]];
How would I go about creating a filter that matches fields in multiple paths?
What about this:
{
"query" : {
"filtered" : {
"filter" : {
"bool" : {
"must" : [
{
"nested": {
"filter": {
"term": {
"accessoires.name.raw": "Climate Control"
}
},
"path": "accessoires"
}
},
{
"nested": {
"filter": {
"term": {
"vestiging.name_dtc.raw": "Location X"
}
},
"path": "vestiging"
}
},
{
"term": {
"key": "33e75ff09dd6"
}
}
]
}
}
}
}
}
I think the problem you are having is a result of incorrect usage of the nested filter although it is a bit difficult to get the exact problem from the exception message. Essentially if you want to combine two nested filters, you will have to group them using bool or and filters.
I have reduced the query quite a bit for the sake of a smaller post. I do not have the post_filter since you don't have any aggregations in your example. I replaced the inner bool filters with just the single term filter that they have and tagged on that additional key (term) filter. But you can continue using your query structure and expand it as you need with the main fix addressing how the two nested filters are put together.

Related Links

Combining log entries with logstash
How to import CSV data using Logstash for field type completion in Elasticsearch suggester
How can I interpret the result of percentiles aggregation type
elastic search select fields to return in aggregation
How to Focus Search On One Part of a Document
How to calculate cooccurrences on a set of texts with Elasticsearch
elasticsearch edge_ngrams analyzer is not found
Double wildcard in query causes weird highlighting for plain/fast vectors elasticsearch highlighters
Get Elasticsearch response in DataTable in C#.Net
Elasticsearch NoNodeAvailableException issue
Why Elasticsearch snapshot stats number_of_files differs from actual indices count?
Specifying data type and analyzer while creating index
elasticsearch regroups aggs by regex
get unique values from elasticsearch
Elasticsearch dies on primary node at random times. What should I look for in troubleshooting?
elasticsearch problems with queries

Categories

HOME
opengl
firebase
lambda
braintree
docker-cloud
tibco
visualforce
sentry
angular-meteor
graphql-js
sap-fiori
jquery-file-upload
ex
twisted
pinterest
rest-assured
cloudsim
parceler
adminlte
gitkraken
sqlplus
restier
web-push
managed-c++
onchange
ninject
sales
dotcms
winsock
windowsiot
reporting
advanced-filter
bean-validation
spinner
love2d
variable-variables
yoast
optionaldataexception
morphline
git-tfs
reverse-dns
nothing
scala-breeze
webvtt
exc-bad-access
wikimapia
mechanicalturk
bpms
logical
openquery
xcode8-beta4
fiber
bbc-micro
gnucash
simian
cortana
largenumber
nastran
libz
kefir.js
com0com
deque
jolie
famo.us
nidaqmx
aho-corasick
code-complexity
senchatouch-2.4
hyphen
application-server
dynamic-rdlc-generation
proc-open
oembed
2d-vector
image-formats
word-frequency
navigationcontroller
memory-pool
multidrop-bus
servercontrol
boost-foreach
kernel32
ognl
anonymous-types
libxslt
android-2.1-eclair
eventaggregator
spring-modules
motif
twitter-feed
acceleration
account-management

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile