1

I try to get data with curl and I run the query in this way:

curl -XGET '<ip>:9200/info-2019.08.21/_search?pretty' -H 'Content-Type: application/json' -d '
{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "name" : "TP-01"
          }
        },
        {
          "query_string": {
            "default_field": "_all",
            "query": "*"
          }
        }
      ]
    }
  }
}'

But I get this response but no data return

  "hits" : {
    "total" : 0,
    "max_score" : null,
    "hits" : [ ]
  }

but I have check the index with the curl command as below,

curl -XGET '<ip>:9200/info-2019.08.21/_search?pretty'

I can get the record as below,

{
    "_index" : "info-2019.08.21",
    "_type" : "customer",
    "_score" : 1.0,
    "_source" : {
      "name" : "TP-01",
      "geoip" : {
        "country" : "US",
        "city" : "NY",
        "long" : 125.683899,
        "lat" : 25.1469,
        "coordinates" : [
          125.683899,
          25.1469
        ]
      },
      "name" : "TP-01"
    }
  }
]

}

What I am doing wrong?

3
  • You need to add some space around -H Commented Sep 5, 2019 at 7:49
  • 3
    Can you share the mapping of your index? Commented Sep 5, 2019 at 8:43
  • guessing it's the result of the standard analyzer removing the hyphen. Try changing your query to use the keyword field: "name.keyword": "TP-01" Commented Sep 5, 2019 at 19:34

1 Answer 1

1

It's hard to give you an exact answer without seeing the index mapping, but I can guess two things:

  1. Name might be a text field. As you can see here, a term query is a bad choice for a text field, since the text field has some standard analyzers. Change your query to aa match query and it should work
  2. What version of ES are you using? I believe the _all field has been deprecated since ES 6. I'm not sure what the end goal is of your second query part, but to search all fields you can just leave this part away, or use a wildcard as the default field.

So for my setup and without custom mapping, your query could look like this:

"query": {
  "bool": {
    "must": [
      {
        "match": {
          "name": {
            "query": "TP-01"
          }
        }
      },
      {
        "query_string": {
          "query": "*"
        }
      }
    ]
  }
}
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.