1

I'm trying to learn Elasticsearch and I have an index with 8 documents. When I run the request (GET):

{
    "query": {
        "match_all" : {}
    }
}

The response is:

{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 8,
      "relation": "eq"
    },
    "max_score": 1.0,
    "hits": [
      {
        "_index": "el1",
        "_type": "_doc",
        "_id": "X5jGjXgB0p8Gz5z3KdFE",
        "_score": 1.0,
        "_source": {
          "itemId": "01",
          "curriculumId": "curriculum01",
          "disciplineId": "discipline01"
        }
      },
      {
        "_index": "el1",
        "_type": "_doc",
        "_id": "YJjGjXgB0p8Gz5z3eNH4",
        "_score": 1.0,
        "_source": {
          "doc": {
            "itemId": "02",
            "curriculumId": "curriculum01",
            "disciplineId": "discipline02"
          }
        }
      },
      {
        "_index": "el1",
        "_type": "_doc",
        "_id": "YZjGjXgB0p8Gz5z3jdHN",
        "_score": 1.0,
        "_source": {
          "doc": {
            "itemId": "03",
            "curriculumId": "curriculum02",
            "disciplineId": "discipline01"
          }
        }
      },
      {
        "_index": "el1",
        "_type": "_doc",
        "_id": "YpjGjXgB0p8Gz5z3tdHl",
        "_score": 1.0,
        "_source": {
          "doc": {
            "itemId": "04",
            "curriculumId": "curriculum02",
            "disciplineId": "discipline02"
          }
        }
      },
      {
        "_index": "el1",
        "_type": "_doc",
        "_id": "Y5jGjXgB0p8Gz5z3w9Gx",
        "_score": 1.0,
        "_source": {
          "doc": {
            "itemId": "01",
            "curriculumId": "curriculum01",
            "disciplineId": "discipline01"
          }
        }
      },
      {
        "_index": "el1",
        "_type": "_doc",
        "_id": "ZJjGjXgB0p8Gz5z30NF5",
        "_score": 1.0,
        "_source": {
          "doc": {
            "itemId": "02",
            "curriculumId": "curriculum01",
            "disciplineId": "discipline02"
          }
        }
      },
      {
        "_index": "el1",
        "_type": "_doc",
        "_id": "ZZjGjXgB0p8Gz5z33NHI",
        "_score": 1.0,
        "_source": {
          "doc": {
            "itemId": "03",
            "curriculumId": "curriculum02",
            "disciplineId": "discipline01"
          }
        }
      },
      {
        "_index": "el1",
        "_type": "_doc",
        "_id": "ZpjGjXgB0p8Gz5z36dE1",
        "_score": 1.0,
        "_source": {
          "doc": {
            "itemId": "03",
            "curriculumId": "curriculum02",
            "disciplineId": "discipline02"
          }
        }
      }
    ]
  }
}

It has all my documents. But if I run this other request (GET):

{
    "query": {
        "match" : {"disciplineId": "discipline01"}
    }
}

It returns just the first document, and if I change it do "discipline02" it returns nothing. The same happens to the other fields. What I'm doing wrong? I already tried using size:"10" but it doesn't seems to work (I think the default size is already 10).

I'm running this docker image and sending the requests with Insomnia.

1 Answer 1

3

Only the first document is in this format

{
  "itemId": "01",
  "curriculumId": "curriculum01",
  "disciplineId": "discipline01"
}

Rest all document are in this format

{
  "doc": {
    "itemId": "02",
    "curriculumId": "curriculum01",
    "disciplineId": "discipline02"
  }
}

Modify your query as

{
  "query": {
    "match": {
      "doc.disciplineId": "discipline02"      // note this
    }
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.