Elasticsearch query yeilds no results

Ranger

I'm new to elasticsearch and having some problems with a query. I can't seem to perform a query based on my "userid" field. Here is the mapping for my index.

{
    "testindex" : {
       "mappings" : {
          "properties" : {
             "timestamp" : {
                "type" : "date"
             },
             "content" : {
                "fields" : {
                   "keyword" : {
                      "type" : "keyword",
                      "ignore_above" : 256
                   }
                },
                "type" : "text"
             },
             "userid" : {
                "fields" : {
                   "keyword" : {
                      "type" : "keyword",
                      "ignore_above" : 256
                   }
                },
                "type" : "text"
             }
          }
       },
       "aliases" : {},
       "settings" : {
          "index" : {
             "creation_date" : "1605323501230",
             "number_of_shards" : "1",
             "number_of_replicas" : "1",
             "version" : {
                "created" : "7090399"
             },
             "uuid" : "<removed>",
             "provided_name" : "testindex"
          }
       }
    }
 }

Here is a document in my cluster when retrieved by the document id.

 {
    "_index":"testindex",
    "_type":"_doc",
    "_id":"d757422a-acf4-4ab0-89f5-bb79b2e2c699",
    "_version":1,
    "_seq_no":1,
    "_primary_term":1,
    "found":True,
    "_source":{
       "userid":"9fe3ba41-780f-448d-8c99-c0440a7ba3f0",
       "content":"testing, testing 12",
       "timestamp":"2020-11-15T05:33:06.615631+00:00"
    }
 }

Here is a query I'm trying based on the userid field.

{
   "query":{
      "bool":{
         "should":{
            "term":{
               "userid":"9fe3ba41-780f-448d-8c99-c0440a7ba3f0"
            }
         }
      }
   }
}

I do not get any results, and the explain output is not helpful.

{
   "_index":"testindex",
   "_type":"_doc",
   "_id":"d757422a-acf4-4ab0-89f5-bb79b2e2c699",
   "matched":False,
   "explanation":{
      "value":0.0,
      "description":"no matching term",
      "details":[
         
      ]
   }
}

What am I doing wrong?

Bhavya

The term query is looking for exact matches, for that you need to use keyword field

Search Query:

{
   "query":{
      "bool":{
         "should":{
            "term":{
               "userid.keyword":"9fe3ba41-780f-448d-8c99-c0440a7ba3f0"
            }
         }
      }
   }
}

Search Result:

"hits": [
      {
        "_index": "64845089",
        "_type": "_doc",
        "_id": "1",
        "_score": 0.2876821,
        "_source": {
          "userid": "9fe3ba41-780f-448d-8c99-c0440a7ba3f0",
          "content": "testing, testing 12",
          "timestamp": "2020-11-15T05:33:06.615631+00:00"
        }
      }
    ]

Search Query using Match Query:

The userid field is most probably indexed with the standard analyzer which will generate the following tokens:

{
  "tokens": [
    {
      "token": "9fe3ba41",
      "start_offset": 0,
      "end_offset": 8,
      "type": "<ALPHANUM>",
      "position": 0
    },
    {
      "token": "780f",
      "start_offset": 9,
      "end_offset": 13,
      "type": "<ALPHANUM>",
      "position": 1
    },
    {
      "token": "448d",
      "start_offset": 14,
      "end_offset": 18,
      "type": "<ALPHANUM>",
      "position": 2
    },
    {
      "token": "8c99",
      "start_offset": 19,
      "end_offset": 23,
      "type": "<ALPHANUM>",
      "position": 3
    },
    {
      "token": "c0440a7ba3f0",
      "start_offset": 24,
      "end_offset": 36,
      "type": "<ALPHANUM>",
      "position": 4
    }
  ]
}

So either you can use the above term query for an exact match or you can use the match query as shown below

 {
       "query":{
          "bool":{
             "should":{
                "match":{
                   "userid":"9fe3ba41-780f-448d-8c99-c0440a7ba3f0"
                }
             }
          }
       }
    }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Are ElasticSearch query results cached?

From Dev

Filter Then Sort Results By Query in ElasticSearch

From Dev

Elasticsearch Geoshape query false results

From Dev

Elasticsearch query results in 'No query registered for [must]'

From Dev

ElasticSearch NEST term query returns no results

From Dev

Make a flat array from Elasticsearch query results

From Dev

Why is ElasticSearch match query returning all results?

From Dev

Elasticsearch term query does not give any results

From Dev

Elasticsearch inconsistent query results with analyzed string

From Dev

Elasticsearch bool filter query return results

From Dev

Make a flat array from Elasticsearch query results

From Dev

ElasticSearch NEST term query returns no results

From Dev

Elasticsearch OR filtered query does not return results

From Dev

Do query results impact elasticsearch phrase suggestions?

From Dev

multi_match query returning no results elasticsearch

From Dev

Elasticsearch DSL query - Get all matching results

From Dev

Elasticsearch: Match query returns wrong results (Java API)

From Dev

Elasticsearch: Why is my query returning too many results?

From Dev

ElasticSearch not returning results for terms query against string property

From Dev

elasticsearch getting too many results, need help filtering query

From Dev

Fewer than Expected Results from Elasticsearch's Fuzzy Query

From Dev

Query with Nest field boosting returning no results from Elasticsearch

From Dev

Elasticsearch 2.x, query for tag, and sort results by tag weigth

From Dev

Python Elasticsearch query not returning the expected results when running subsequent calls

From Dev

NEST elasticsearch.NET search query not returning results (part 2)

From Dev

ElasticSearch: getting facets from all results with filter query

From Dev

Deleting data results related to a query using Java API Elasticsearch

From Dev

elasticsearch match query used against a field array returns bad results

From Dev

Elasticsearch 2.x, query for tag, and sort results by tag weigth

Related Related

  1. 1

    Are ElasticSearch query results cached?

  2. 2

    Filter Then Sort Results By Query in ElasticSearch

  3. 3

    Elasticsearch Geoshape query false results

  4. 4

    Elasticsearch query results in 'No query registered for [must]'

  5. 5

    ElasticSearch NEST term query returns no results

  6. 6

    Make a flat array from Elasticsearch query results

  7. 7

    Why is ElasticSearch match query returning all results?

  8. 8

    Elasticsearch term query does not give any results

  9. 9

    Elasticsearch inconsistent query results with analyzed string

  10. 10

    Elasticsearch bool filter query return results

  11. 11

    Make a flat array from Elasticsearch query results

  12. 12

    ElasticSearch NEST term query returns no results

  13. 13

    Elasticsearch OR filtered query does not return results

  14. 14

    Do query results impact elasticsearch phrase suggestions?

  15. 15

    multi_match query returning no results elasticsearch

  16. 16

    Elasticsearch DSL query - Get all matching results

  17. 17

    Elasticsearch: Match query returns wrong results (Java API)

  18. 18

    Elasticsearch: Why is my query returning too many results?

  19. 19

    ElasticSearch not returning results for terms query against string property

  20. 20

    elasticsearch getting too many results, need help filtering query

  21. 21

    Fewer than Expected Results from Elasticsearch's Fuzzy Query

  22. 22

    Query with Nest field boosting returning no results from Elasticsearch

  23. 23

    Elasticsearch 2.x, query for tag, and sort results by tag weigth

  24. 24

    Python Elasticsearch query not returning the expected results when running subsequent calls

  25. 25

    NEST elasticsearch.NET search query not returning results (part 2)

  26. 26

    ElasticSearch: getting facets from all results with filter query

  27. 27

    Deleting data results related to a query using Java API Elasticsearch

  28. 28

    elasticsearch match query used against a field array returns bad results

  29. 29

    Elasticsearch 2.x, query for tag, and sort results by tag weigth

HotTag

Archive