0
votes

because when I use the (From / Size) function in the query, it doesn't return the doc that I hope to return. For example, I have 5 docs in elasticsearch, all docs in the sequence, _id 1, _id 2, _id 3, _id 4, id _5.

The doc ID 5 has the word (car) and In the query I say to get the word (car) from ID 4 ("from": 4, "size": 1,) it does not return the ID 5 it has the word (car), but in the query I put information that exists in doc 5, so I should bring doc 5, but it doesn't and says it didn't find a result. If I put the query from ID 0 ("from": 0, "size": 1,) it finds ID 5. It seems that elasticsearch makes confusion with ID's. Can you tell me what happens to ID's?

The query below from ID 4 does not return ID 5, but if I put the query from ID 0, then it returns ID 5

{
"from": 4, "size": 1,
"query": {
"multi_match": {
"query": "car",

   "type": "cross_fields",
   "fields": ["title", "description", "url"],
   "operator": "and"
}
}
}
3
From and size are for pagination of records returned by query. If your query(search on car) returns five records then from:4 size : 1 will return 5th record. If your query returns only 1 record then from:4 size:0 will not return anything as there is no 5 th record in resultjaspreet chahal
@jaspreet but I didn't put size (zero) ("from": 4, "size": 0) I put ("from": 4, "size": 1), so I should bring the _id 5 that has the word (car)Jean

3 Answers

0
votes

size and from are applied after the query filters are applied.

Also, your "sorted" doc IDs don't necessarily guarantee the retrieval order, esp. when scoring comes into play.

If you share your docs & mapping, we could help you out further.

0
votes

in the query below I send the results that have the field (pgrk) between 9 and 10 and have the field (url_length) less than 4, but the record with (_id 15) satisfies what I requested, but only returns the record of (_id 15) if I put ("from": 0,"size": 1,) if I put ("from": 1,"size": 1,) does not return the record (_id 15)

{
    "from": 1,
    "size": 1,
    "sort": [
        {
            "pgrk": {
                "order": "desc"
            }
        },
        {
            "url_length": {
                "order": "asc"
            }
        }
    ],
    "query": {
        "bool": {
            "must": {
                "multi_match": {
                    "query": "netflix",
                    "type": "cross_fields",
                    "fields": [
                        "titulo",
                        "descricao",
                        "url"
                    ],
                    "operator": "and"
                }
            },
            "filter": [
                {
                    "range": {
                        "pgrk": {
                            "gte": 9,
                            "lte" : 10
                        }
                    }
                },
                {
                    "range": {
                        "url_length": {
                           "lt" : 4
                        }
                    }
                }
            ]
        }
    }
}

if I put ("from": 1, "size": 1,) it does not return the record (_id 15) that has "url_length = 2" returns the doc of _id 14 that has "url_length = 3" as shown below:

{
  "took": 0,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 2,
      "relation": "eq"
    },
    "max_score": null,
    "hits": [
      {
        "_index": "teste",
        "_type": "_doc",
        "_id": "14",
        "_score": null,
        "_source": {
          "url": "www.333.com",
          "titulo": "netflix netflix netflix netflix netflix netflix netflix netflix netflix netflix",
          "descricao": "tudo sobre netflix netflix netflix netflix netflix netflix",
          "pgrk": "10",
          "url_length": "3"
        },
        "sort": [
          10,
          3
        ]
      }
    ]
  }
}

if I put ("from": 0, "size": 1,) then it returns the record (_id 15) that has "url_length = 2"

{
  "took": 0,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 2,
      "relation": "eq"
    },
    "max_score": null,
    "hits": [
      {
        "_index": "teste",
        "_type": "_doc",
        "_id": "15",
        "_score": null,
        "_source": {
          "url": "www.netflix.yahoo.com",
          "titulo": "melhor filme",
          "descricao": "tudo sobre series",
          "pgrk": "10",
          "url_length": "2"
        },
        "sort": [
          10,
          2
        ]
      }
    ]
  }
}
0
votes

how do I always return the docs with the lowest value in the "url_length" field?

because I had it searched ("from": 1, "size": 1,) and didn't bring the record of (_id 15) that has the ("url_length" = 2) brought the record of (_id 14) that has the (" url_length "= 3)