7

I have a document indexed in elasticsearch:

{
    "content":"Some content with @someone mention",
    "mentions":["someone"],
    "userId":"4dff31eaf8815f4df04e2d62"
}

I try to find it with a query:

{
    "query": {
        "filtered": {
            "filter": { "term":{"userId":"4dff31eaf8815f4df04e2d62"} },
            "query": {
                term: {"mentions":"someone"}
            }
        }
    }
}

and receive no results.

In the same time query for content works fine:

{
    "query": {
        "filtered": {
            "filter": { "term":{"userId":"4dff31eaf8815f4df04e2d62"} },
            "query": {
                "term": {"content":"some"}
            }
        }
    }
}

Is some special syntax required for search through arrays? I found several topics [1, 2] about arrays in elasticsearch, but there is no direct answer.

UPD Get Mapping call returns the next result:

{
    "records": {
        "all":{
            "properties":{
                "content":{"type":"string"},
                "userId":{"type":"string"},
                "mentions":{"type":"string"}
            }
        }
    }
}

UPD2 I found the source of problem. I accidentally introduced an error into my question. The username I actually had in DB was in form "some_one" (underscore is significant). So standard index split it into 2 words and query for "some_one" of cause failing.

4
  • I cannot reproduce it with default settings/mapping. What is the mapping for this field? Commented Jun 24, 2011 at 16:55
  • @imotov AFAIK there is no any non-default mapping. I updated question with the "get mapping" api call result. Commented Jun 27, 2011 at 8:52
  • 1
    That's how it looks like when I run it on my machine: gist.github.com/1048874 Do you get different results? I also noticed that term in the first query is not surrounded by quotes. Could this be a problem? Commented Jun 27, 2011 at 13:46
  • @imotov i did a mistake, when posted this question (see upd2). But thank you, without your example I would newer done the correct experiment. Commented Jun 27, 2011 at 14:47

1 Answer 1

2

This is correct usage, as your update mentions.

If you import a document with a "mentions" array, searching on a matching array item, referring to it as "mentions", will retrieve the document. I had the same issue and verified it myself just now.

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.