Query DSL

    For example, the following request performs a simple search to search for a field that has a value of queen.

    Sample request

    Sample response

    1. {
    2. "took": 87,
    3. "timed_out": false,
    4. "_shards": {
    5. "total": 68,
    6. "successful": 68,
    7. "skipped": 0,
    8. "failed": 0
    9. },
    10. "hits": {
    11. "total": {
    12. "value": 4080,
    13. "relation": "eq"
    14. },
    15. "max_score": 4.4368687,
    16. "hits": [
    17. {
    18. "_index": "new_shakespeare",
    19. "_id": "28559",
    20. "_score": 4.4368687,
    21. "_source": {
    22. "type": "line",
    23. "line_id": 28560,
    24. "play_name": "Cymbeline",
    25. "speech_number": 20,
    26. "line_number": "1.1.81",
    27. "speaker": "QUEEN",
    28. "text_entry": "No, be assured you shall not find me, daughter,"
    29. }

    Sample request

    Sample Response

    1. {
    2. "took": 39,
    3. "timed_out": false,
    4. "_shards": {
    5. "total": 68,
    6. "successful": 68,
    7. "skipped": 0,
    8. "failed": 0
    9. },
    10. "hits": {
    11. "total": {
    12. "value": 5837,
    13. "relation": "eq"
    14. },
    15. "max_score": 7.8623476,
    16. "hits": [
    17. {
    18. "_index": "new_shakespeare",
    19. "_id": "100763",
    20. "_score": 7.8623476,
    21. "_source": {
    22. "type": "line",
    23. "line_id": 100764,
    24. "play_name": "Troilus and Cressida",
    25. "speech_number": 43,
    26. "line_number": "3.1.68",
    27. "speaker": "PANDARUS",
    28. }
    29. },
    30. {
    31. "_id": "28559",
    32. "_score": 5.8923807,
    33. "_source": {
    34. "type": "line",
    35. "line_id": 28560,
    36. "play_name": "Cymbeline",
    37. "speech_number": 20,
    38. "line_number": "1.1.81",
    39. "speaker": "QUEEN",
    40. "text_entry": "No, be assured you shall not find me, daughter,"
    41. }
    42. }
    43. ]
    44. }
    45. }

    The OpenSearch query DSL comes in three varieties: term-level queries, full-text queries, and boolean queries. You can even perform more complicated searches by using different elements from each variety to find whatever data you need.

    The examples below illustrate values containing special characters that will be parsed improperly by the standard analyzer. In this example, the existence of the hyphen/minus sign in the value prevents the analyzer from distinguishing between the two different users for user.id and interprets them as one and the same:

    1. {
    2. "bool": {
    3. "must": {
    4. "match": {
    5. "user.id": "User-2"
    6. }
    7. }
    8. }
    9. }

    To avoid this circumstance when using either query DSL or the REST API, you can use a custom analyzer or map the field as keyword, which performs an exact-match search. See for the latter option.

    For a list of characters that should be avoided when field type is , see Word Boundaries.