TermFilter and Array-Fields - bug or intended behaviour


(K.B.) #1

Hello,

I if one has an ArrayField like

field = ["Val1","Val2","Val3"]

and its not_analyzed by mapping then in case a Filter is tried to be
put over it:

FilterBuilders.termFilter("field", "Val1");

the resulting query the flter is put to will allways have 0 results.

Is this intended or a bug?

Best


(Shay Banon) #2

This filter will work. Have you called refresh before you executed the search and after you indexed the document? If it still does not work, gist a curl recreation (http://www.elasticsearch.org/help).
On Thursday, March 10, 2011 at 3:33 PM, K.B. wrote:

Hello,

I if one has an ArrayField like

field = ["Val1","Val2","Val3"]

and its not_analyzed by mapping then in case a Filter is tried to be
put over it:

FilterBuilders.termFilter("field", "Val1");

the resulting query the flter is put to will allways have 0 results.

Is this intended or a bug?

Best


(Clinton Gormley) #3

Hi KB

I if one has an ArrayField like

field = ["Val1","Val2","Val3"]

and its not_analyzed by mapping then in case a Filter is tried to be
put over it:

FilterBuilders.termFilter("field", "Val1");

the resulting query the flter is put to will allways have 0 results.

I'm not seeing this. My example shows the correct behaviour:

Are you sure that your field is mapped as not_analyzed?

Try retrieving the mapping from ElasticSearch and see what it thinks the
mapping is.

http://www.elasticsearch.org/guide/reference/api/admin-indices-get-mapping.html

Clint


(K.B.) #4

Hello,

mapping seems correct, ES tells me:

...
linie_mv: {
* index: not_analyzed
* type: string
}
...

as expected (field is called differently here); As all other requests
to these fields work, I expect it to be indexed :slight_smile:

see gist:

If you do a queryString query and add a filter to the builder it will
give you empty returns;

On 10 Mrz., 14:51, Clinton Gormley clin...@iannounce.co.uk wrote:

Hi KB

I if one has an ArrayField like

field = ["Val1","Val2","Val3"]

and its not_analyzed by mapping then in case a Filter is tried to be
put over it:

FilterBuilders.termFilter("field", "Val1");

the resulting query the flter is put to will allways have 0 results.

I'm not seeing this. My example shows the correct behaviour:

https://gist.github.com/864115

Are you sure that your field is mapped as not_analyzed?

Try retrieving the mapping from ElasticSearch and see what it thinks the
mapping is.

http://www.elasticsearch.org/guide/reference/api/admin-indices-get-ma...

Clint


(Clinton Gormley) #5

Hiya

as expected (field is called differently here); As all other requests
to these fields work, I expect it to be indexed :slight_smile:

see gist:

https://gist.github.com/b373610376324745ce3c

If you do a queryString query and add a filter to the builder it will
give you empty returns;

I've updated my example to show your same query with a query string, and
that it does work:

I think your data is not what you think it is.

If you try to recreate this problem from scratch, I think you will find
where your issue is (or failing that, that it now works :slight_smile:

hth

clint


(K.B.) #6

heya clint,

thanks for answer but you're cheating :wink:

You do:

{
"query" : {
"filtered" : {
"query" : {
"query_string" : {
"query" : "*"
}
},
"filter" : {
"term" : {
"field" : "Val1"
}
}
}
}
}

While my java ends up in:

{
"filtered":{
"query":{
"query_string":{
"query":"*"
}
},
"filter":{
"term":{
"field":"Val1"
}
}
}
}

see, you put a big query around your 2 queries, while the java
transformates to the thing shown below - and that gives null back in
elasticsearch-head and gives no error as valid JSON;

My data seems ok as it works with either your JSON code or if I put it
into the first querystring;

Best

On 10 Mrz., 15:59, Clinton Gormley clin...@iannounce.co.uk wrote:

Hiya

as expected (field is called differently here); As all other requests
to these fields work, I expect it to be indexed :slight_smile:

see gist:

https://gist.github.com/b373610376324745ce3c

If you do a queryString query and add a filter to the builder it will
give you empty returns;

I've updated my example to show your same query with a query string, and
that it does work:

https://gist.github.com/864115

I think your data is not what you think it is.

If you try to recreate this problem from scratch, I think you will find
where your issue is (or failing that, that it now works :slight_smile:

hth

clint


(Clinton Gormley) #7

Hi KB

thanks for answer but you're cheating :wink:

see, you put a big query around your 2 queries, while the java
transformates to the thing shown below - and that gives null back in
elasticsearch-head and gives no error as valid JSON;

I'm not cheating :slight_smile: That is the correct syntax when using the HTTP API:

http://www.elasticsearch.org/guide/reference/api/search/query.html

Whatever query you pass in needs to be passed as the value of the
'query' parameter. You can't pass a 'filtered' query as a top level
param.

Note: there was an incorrect example of a filtered query on
http://www.elasticsearch.org/guide/reference/api/search/
which I have now fixed.

clint


(K.B.) #8

Ah, ok,

now thats different then.... ok, the JSON now seems ok and - please
dont ask me why - my java also now works.... haven't changed a line,
just an appserver restart...

Thank you very much for your help,

Best

On 10 Mrz., 16:23, Clinton Gormley clin...@iannounce.co.uk wrote:

Hi KB

thanks for answer but you're cheating :wink:

see, you put a big query around your 2 queries, while the java
transformates to the thing shown below - and that gives null back in
elasticsearch-head and gives no error as valid JSON;

I'm not cheating :slight_smile: That is the correct syntax when using the HTTP API:

http://www.elasticsearch.org/guide/reference/api/search/query.html

Whatever query you pass in needs to be passed as the value of the
'query' parameter. You can't pass a 'filtered' query as a top level
param.

Note: there was an incorrect example of a filtered query onhttp://www.elasticsearch.org/guide/reference/api/search/
which I have now fixed.

clint


(system) #9