Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a query in Elasticsearch 1.x like this:

{"filter": {"and": {"filters": [{"exists": {"field": "body"}}, {"query": {"term": {"accept": "true"}}},
                                      {"exists": {"field": "thumbnail"}}, {"query": {"terms": {
        "content": ["577f6ca06dd5340a97e89923"]}}}, {"range": {
        "date": {"lt": "2018-01-05T04:07:48.901933", "gte": "1963-04-04T04:07:48.901933"}}}, 
                                      {"query": {"terms": {
        "agency": ["577ff7176dd5340a97e899b7"]}}}, {"query": {"terms": {
        "subject": ["578c6c7f6dd5345f3db18e7b"]}}}, {"query": {
        "terms": {"geographic": ["577f78fe6dd5340a97e89948"]}}}]}},
       "fields": ["_id", "link", "title"], "from": 0,
       "sort": {"date": {"order": "desc"}}, "size": 30}

It works in 1.x version but in 5.x version rises an error:

elasticsearch.exceptions.RequestError: TransportError(400, u'parsing_exception', u'Unknown key for a START_OBJECT in [filter].')

What should I do?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
243 views
Welcome To Ask or Share your Answers For Others

1 Answer

Try this query, it should work:

{
  "query": {
    "bool": {
      "filter": [
        {
          "exists": {
            "field": "body"
          }
        },
        {
          "term": {
            "accept": "true"
          }
        },
        {
          "exists": {
            "field": "thumbnail"
          }
        },
        {
          "terms": {
            "content": [
              "577f6ca06dd5340a97e89923"
            ]
          }
        },
        {
          "range": {
            "date": {
              "lt": "2018-01-05T04:07:48.901933",
              "gte": "1963-04-04T04:07:48.901933"
            }
          }
        },
        {
          "terms": {
            "agency": [
              "577ff7176dd5340a97e899b7"
            ]
          }
        },
        {
          "terms": {
            "subject": [
              "578c6c7f6dd5345f3db18e7b"
            ]
          }
        },
        {
          "terms": {
            "geographic": [
              "577f78fe6dd5340a97e89948"
            ]
          }
        }
      ]
    }
  },
  "_source": [
    "_id",
    "link",
    "title"
  ],
  "from": 0,
  "sort": {
    "date": {
      "order": "desc"
    }
  },
  "size": 30
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...