Filter search by a value in a array


(dashaus) #1

HI!
I want filter my search by a value in a array. I have this in ES:

{
"_id" : "BeyKH2Cx",
"occupations" : ["d5ot2bwu","HwmXygzK"],
"name" : "Matthew McConaughey"
},
{
"_id" : "BeyKH2Cx",
"occupations" : ["HwmXygzK"],
"name" : "Matthew Nilan"
}

And i execute a search as below:

GET mongoindex/professionals/_search?search_type=dfs_query_and_fetch
{

"fields" : ["name", "_id","occupations"],

"query": {
"filtered": {
"query": {
"multi_match" : {
"query" : "stephen",
"fuzziness": 2,
"prefix_length": 1,
"fields" : ["artname","realname"],
"analyzer": "simple"
}
},
"filter" : {
"terms" : {
"occupations" : ["3qm3LsHP"]
}
}
}
}
}

But I have 0 results... If instead of "occupations":["3qm3LsHP"], I put
"_id":"BeyKH2Cx" it works, but I need filter by a value in the
"occupations" array. What is the way to make this work?

Thanks!

Best,
Emilio

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/6ea8f5be-7cd7-4caa-876d-00f68002ccd6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(David Pilato) #2

Lowercase your filter as a TermFilter is not analyzed

--
David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 7 mars 2014 à 06:18, Emilio García-Pumarino Álvarez emili.tfe@gmail.com a écrit :

HI!
I want filter my search by a value in a array. I have this in ES:
{
"_id" : "BeyKH2Cx",
"occupations" : ["d5ot2bwu","HwmXygzK"],
"name" : "Matthew McConaughey"
},
{
"_id" : "BeyKH2Cx",
"occupations" : ["HwmXygzK"],
"name" : "Matthew Nilan"
}

And i execute a search as below:

GET mongoindex/professionals/_search?search_type=dfs_query_and_fetch
{

"fields" : ["name", "_id","occupations"],

"query": {
"filtered": {
"query": {
"multi_match" : {
"query" : "stephen",
"fuzziness": 2,
"prefix_length": 1,
"fields" : ["artname","realname"],
"analyzer": "simple"
}
},
"filter" : {
"terms" : {
"occupations" : ["3qm3LsHP"]
}
}
}
}
}

But I have 0 results... If instead of "occupations":["3qm3LsHP"], I put "_id":"BeyKH2Cx" it works, but I need filter by a value in the "occupations" array. What is the way to make this work?

Thanks!

Best,
Emilio

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/6ea8f5be-7cd7-4caa-876d-00f68002ccd6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/027C622E-4FCF-4E7C-BC27-2139DB45710A%40pilato.fr.
For more options, visit https://groups.google.com/d/optout.


(dashaus) #3

Oops! I use instead:
"filter": {
"query": {
"match": {
"occupations": "3qm3LsHP"
}
}
}

And it works! Thanks for detail.

Best,
Emilio

El viernes, 7 de marzo de 2014 06:56:04 UTC, David Pilato escribió:

Lowercase your filter as a TermFilter is not analyzed

--
David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 7 mars 2014 à 06:18, Emilio García-Pumarino Álvarez <emil...@gmail.com<javascript:>>
a écrit :

HI!
I want filter my search by a value in a array. I have this in ES:

{
"_id" : "BeyKH2Cx",
"occupations" : ["d5ot2bwu","HwmXygzK"],
"name" : "Matthew McConaughey"
},
{
"_id" : "BeyKH2Cx",
"occupations" : ["HwmXygzK"],
"name" : "Matthew Nilan"
}

And i execute a search as below:

GET mongoindex/professionals/_search?search_type=dfs_query_and_fetch
{

"fields" : ["name", "_id","occupations"],

"query": {
"filtered": {
"query": {
"multi_match" : {
"query" : "stephen",
"fuzziness": 2,
"prefix_length": 1,
"fields" : ["artname","realname"],
"analyzer": "simple"
}
},
"filter" : {
"terms" : {
"occupations" : ["3qm3LsHP"]
}
}
}
}
}

But I have 0 results... If instead of "occupations":["3qm3LsHP"], I put
"_id":"BeyKH2Cx" it works, but I need filter by a value in the
"occupations" array. What is the way to make this work?

Thanks!

Best,
Emilio

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearc...@googlegroups.com <javascript:>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/6ea8f5be-7cd7-4caa-876d-00f68002ccd6%40googlegroups.comhttps://groups.google.com/d/msgid/elasticsearch/6ea8f5be-7cd7-4caa-876d-00f68002ccd6%40googlegroups.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/bf24b5d5-29f2-411c-8320-455a0cff3629%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(system) #4