Elasticsearch查询没有返回任何内容

时间:2016-04-14 14:43:40

标签: java elasticsearch

我将以下文档编入索引,但是当我运行搜索时它没有返回任何内容,我想知道它是否与查询有关。我正在尝试搜索其中包含单词dog的任何嵌套消息。这是文件:

pip install grip
grip markdown.md

这是我运行curl命令时运行的查询:

{
"_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"
}
}

1 个答案:

答案 0 :(得分:1)

您拥有的映射以及带有稍微修改过的查询的示例文档适用于我:

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": {}
              }
            }
          ]
        }
      }
    }
  }
}'
相关问题