0

I'm trying to filter by terms within an array on elasticsearch documents. This is what the documents look like:

{
    "name": "Foo",
    "id": 10,
    "industries": ["Tech", "Fashion"],
    ...
}

But for the various filter-based queries I try, I've gotten zero results. e.g.:

$ curl -XGET 'http://localhost:9200/_search?pretty=true' -d '
{
    "query": {
        "filtered": {
            "filter": {
                "bool": {
                    "must": [{
                        "terms": {
                            "industries": ["Tech"],
                            "execution": "or"
                        }
                    }]
                }
            },
            "query": {"match_all": {}}
        }
    },
    "from": 0,
    "size": 20
}
'

I've tried about a dozen different queries against various simplifications and filter clauses, e.g. here's a simplified one:

$ curl -XGET 'http://localhost:9200/_search?pretty=true' -d '
{
    "query": {
        "filtered": {
            "filter": {
                "terms": {
                    "industries": ["Tech"],
                    "execution": "or"
                }
            }
        }

    },
    "from": 0,
    "size": 20
}
'

What am I missing here?

3
  • 1
    What analyzer are you using for the industries field? If you are using the default, it will actually lower case and split your stings, which would explain why your filters aren't picking those documents up (e.g., it's looking for "Tech" when only "tech" exists). If you set the mapping to not_analyzed (or use the multi fields option), that might solve your problem. Commented Apr 16, 2014 at 20:19
  • Yep, that did it. Thanks Chris! If you make it an answer I can accept it. Commented Apr 16, 2014 at 21:47
  • Just did - thanks! Glad that solved your problem. Commented Apr 21, 2014 at 19:01

1 Answer 1

1

What analyzer are you using for the industries field? If you are using the default, it will actually lower case and split your stings, which would explain why your filters aren't picking those documents up (e.g., it's looking for "Tech" when only "tech" exists). If you set the mapping to not_analyzed (or use the multi fields option), that might solve your problem.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.