I have a strange behaviour with ES (but I think my schema/query is wrong).
For example a simple category > article index like this :
curl -XPUT 'http://localhost:9200/mm/article/_mapping' -d '
{
"article" : {
"properties" : {
"cat" : {
"type" : "object",
"properties" : {
"cat_id" : {
"type" : "long"
}
}
},
"article_id" : {
"type" : "long"
}
}
}
}'
curl -XPUT 'http://localhost:9200/mm/cat/_mapping' -d '
{
"cat" : {
"properties" : {
"cat_id" : {
"type" : "long"
},
"title" : {
"type" : "string"
}
}
}
}'
And some data :
curl -XPUT 'http://localhost:9200/mm/article/1' -d
'{"article_id":1,"cat":{"cat_id":1}}'
curl -XPUT 'http://localhost:9200/mm/article/2' -d
'{"article_id":2,"cat":{"cat_id":1}}'
curl -XPUT 'http://localhost:9200/mm/cat/1' -d '{"cat_id":1,"title":"cat
title"}'
I want to filter articles by category ID :
curl -XGET 'http://localhost:9200/mm/_search' -d
'{"filter":{"and":[{"type":{"value":"article"}},{"term":{"cat.cat_id":1}}]}}'
return 0 hits instead of 2.
I guess this is because cat.cat_id is at the same time a {sub}.{field} of
"article" type and {type}.{field} of "cat" type.
So I found that a query like this :
curl -XGET 'http://localhost:9200/mm/_search' -d
'{"filter":{"and":[{"type":{"value":"article"}},{"term":{"article.
cat.cat_id":1}}]}}'
returns my 2 articles, good !
Is it safe to _search on a full index and use type prefixed name in filters
? Can't find in the documentation.
Of course I could rewrite the query like this :
curl -XGET 'http://localhost:9200/mm/article/_search' -d
'{"filter":{"term":{"cat.cat_id":1}}}'
and it works, but I do need a _search on multiple types.
Thanks for your help.
--