Daniel Buckle
Daniel Buckle

Reputation: 628

Elasticsearch query not returning anything

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": {}
                }
            }]
        }
    }
}
}

Upvotes: 0

Views: 62

Answers (1)

Andrei Stefan
Andrei Stefan

Reputation: 52368

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": {}
              }
            }
          ]
        }
      }
    }
  }
}'

Upvotes: 1

Related Questions