0

I have the following document indexed but when I run the search it's not returning anything, I was wondering if its an issue with the query. I am trying to search for any of the nested messages that have the word dogs in it. Here is the document:

{
"_index": "thread_and_messages",
"_type": "thread",
"_id": "3",
"_score": 1.0,
"_source": {
    "thread_id": 3,
    "thread_name": "I play the guitar",
    "created": "Wed Apr 13 2016",
    "thread_view": 2,
    "first_nick": "Test User",
    "messages": [{
        "message_text": " I like dogs",
        "message_id": 13,
        "message_nick": "Test"
    }],
    "site_name": "Test Site"
}
}

Here is the query I am running when I run the curl command:

{
"function_score": {
    "functions": [{
        "field_value_factor": {
            "field": "thread_view",
            "modifier": "log1p",
            "factor": 2
        }
    }],
    {"query": {
        "bool": {
            "should": [{
                "match": {
                    "thread_name": "dogs"
                }
            }, {
                "nested": {
                    "path": "messages",
                    "query": {
                        "bool": {
                            "should": [{
                                "match": {
                                    "messages.message_text": "dogs"
                                }
                            }]
                        }
                    },
                    "inner_hits": {}
                }
            }]
        }
    }
}
}
4
  • Are you sure that messages.message_text is an analyzed field? Commented Apr 14, 2016 at 14:51
  • I haven't defined whether this filed is analyzed or not, should I be defining it as analyzed? Commented Apr 14, 2016 at 14:55
  • Provide a output from : curl -XGET localhost:9200/thread_and_messages/ Commented Apr 14, 2016 at 15:53
  • { "thread_and_messages": { "aliases": {}, "mappings": { "thread": { "properties": { "created": { "type": "string" }, "first_nick": { "type": "string" }, "messages": { "type": "nested", "include_in_parent": true, "properties": { "message_id": { "type": "string" }, "message_nick": { "type": "string" }, "message_text": { "type": "string" } } }} Commented Apr 14, 2016 at 15:55

1 Answer 1

1

The mapping you have plus the sample document with a slightly modified query works for me:

curl -XGET "http://localhost:9200/thread_and_messages/thread/_search" -d'
{
  "query": {
    "function_score": {
      "functions": [
        {
          "field_value_factor": {
            "field": "thread_view",
            "modifier": "log1p",
            "factor": 2
          }
        }
      ],
      "query": {
        "bool": {
          "should": [
            {
              "match": {
                "thread_name": "dogs"
              }
            },
            {
              "nested": {
                "path": "messages",
                "query": {
                  "bool": {
                    "should": [
                      {
                        "match": {
                          "messages.message_text": "dogs"
                        }
                      }
                    ]
                  }
                },
                "inner_hits": {}
              }
            }
          ]
        }
      }
    }
  }
}'
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.