Please excuse me if it is too basic, I am just starting with elastic
search.
I have three fields, fieldA, fieldB, fieldC and I want to search where
fieldA = "xxx", fieldB is null and facets for fieldC.
I was trying to construct the query step by step.
Step1: get documents where fieldA = "xxx"
{"query" :
{ "term" : {"fieldA" : "xxx"}}
}
Step2: get documents where fieldB is not null to not it later(I
couldn't find any query in docs checking for null)
{"query" :
{ "wildcard" : {"fieldB": "?*"}}
}
Step3: combine first two queries
{"query" :
{ "term" : {"fieldA" : "xxx"}},
{ "wildcard" : {"fieldB": "?*"}}
}
But this query always fails. I have tried many different combinations,
but nothing worked. I also wasn't able to get the not query working on
step two.
Any suggestions on how it should be done would be greatly appreciated.
Thanks.
Hi Rubish
I have three fields, fieldA, fieldB, fieldC and I want to search where
fieldA = "xxx", fieldB is null and facets for fieldC.
Try this:
curl -XGET 'http://127.0.0.1:9200/_all/_search?pretty=1' -d '
{
"query" : {
"filtered" : {
"query" : {
"term" : {
"fieldA" : "xxx"
}
},
"filter" : {
"missing" : {
"field" : "fieldB"
}
}
}
},
"facets" : {
"field_c_facets" : {
"terms" : {
"field" : "fieldC"
}
}
}
}
'
clint
Thanks Mate! Just got the {missing} working, now need to get on with facets.
Cheers!
On Wed, Apr 27, 2011 at 7:38 PM, Clinton Gormley clinton@iannounce.co.ukwrote:
Hi Rubish
I have three fields, fieldA, fieldB, fieldC and I want to search where
fieldA = "xxx", fieldB is null and facets for fieldC.
Try this:
curl -XGET 'http://127.0.0.1:9200/_all/_search?pretty=1' -d '
{
"query" : {
"filtered" : {
"query" : {
"term" : {
"fieldA" : "xxx"
}
},
"filter" : {
"missing" : {
"field" : "fieldB"
}
}
}
},
"facets" : {
"field_c_facets" : {
"terms" : {
"field" : "fieldC"
}
}
}
}
'
clint