ElasticSearch

时间:2016-07-09 09:33:04

标签: elasticsearch indexoutofboundsexception

{
  "query": {
    "bool": {
      "must": [
        {
          "bool": {
            "should": [
              {
                "term": {
                  "content": {
                    "value": "远磐",
                    "boost": 5757544300000000000
                  }
                }
              },
              {
                "term": {
                  "title": {
                    "value": "远磐",
                    "boost": 5757544300000000000
                  }
                }
              }
            ],
            "minimum_should_match": "1"
          }
        },
        {
          "bool": {
            "should": [
              {
                "term": {
                  "title": {
                    "value": "互联",
                    "boost": 6456151
                  }
                }
              },
              {
                "term": {
                  "content": {
                    "value": "杭州远磐互联科技有限公司",
                    "boost": 3.3149317e+37
                  }
                }
              }
            ],
            "minimum_should_match": "1"
          }
        }
      ]
    }
  },
  "from": 0,
  "size": 10
}

当我在搜索结果时创建elasticsearch查询时,错误就会发生。

我不知道这个错误。

错误:

IndexOutOfBoundsException[docID must be >= 0 and < maxDoc=158 (got docID=2147457971)]

并且所有匹配的得分为零。

enter image description here 整个错误:

请帮忙!

此致

1 个答案:

答案 0 :(得分:1)

我发布此答案,因为它无法发布为评论。这是优化的查询。 在缓存过滤器时,最好使用过滤器而不是查询。你应该避免提供如此大的数字,因为它是资源匮乏。尝试相对较小的数字。

{
  "query": {
    "bool": {
      "must": {
        "match_all": {}
      },
      "filter": {
        "and": [
          {
            "or": [
              {
                "term": {
                  "content": "远磐"
                }
              },
              {
                "term": {
                  "title": "远磐"
                }
              }
            ]
          },
          {
            "or": [
              {
                "term": {
                  "content": "互联"
                }
              },
              {
                "term": {
                  "title": "杭州远磐互联科技有限公司"
                }
              }
            ]
          }
        ]
      },
      "should": [
        {
          "term": {
            "content": "远磐",
            "boost": 10
          }
        },
        {
          "term": {
            "title": "远磐",
            "boost": 5
          }
        },
        {
          "term": {
            "content": "互联",
            "boost": 3
          }
        },
        {
          "term": {
            "title": "杭州远磐互联科技有限公司",
            "boost": 20
          }
        }
      ],
      "minimum_should_match": 1,
      "boost": 1
    }
  },
  "from":0,
  "size":10
}