0

I am trying to search specific field and value using elasticsearch boolean query. I am hitting this endpoint "http://localhost:9200/index/_search" using python requests.

get sports/_search {"query":
    {
        "bool":
        {
            "must":
            [{
                "match":
                {
                    "sport":"cricket"
                }
            },
            {
                "match":
                {
                    "age":"42"
                }
            }]
        }
    }
}

I am getting this response, here I am using python requests to get response.

'{"took":2,"timed_out":false,"_shards":{"total":5,"successful":5,"skipped":0,"failed":0},"hits":{"total":0,"max_score":null,"hits":[]}}'

My index document is:

{
  "took" : 2,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 1,
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "sports",
        "_type" : "articles",
        "_id" : "1",
        "_score" : 1.0,
        "_source" : {
          "mappings" : {
            "person2" : {
              "details" : {
                "debut" : "23 December 2004",
                "awards" : "Padma Bhushan, Padma Shri, Rajiv Gandhi Khel Ratna",
                "name" : "Dhoni",
                "country" : "India",
                "dob" : "7 July 1981",
                "gender" : "Male",
                "age" : "36",
                "sport" : "Cricket",
                "current_status" : "on-ground"
              }
            },
            "person3" : {
              "details" : {
                "debut" : "23 December 2004",
                "awards" : "Padma Bhushan, Padma Shri, Rajiv Gandhi Khel Ratna",
                "name" : "Saina Nehwal",
                "country" : "India",
                "dob" : "17 March 1990",
                "gender" : "Female",
                "age" : "28",
                "sport" : "Badmiton",
                "current_status" : "on-ground"
              }
            },
            "person1" : {
              "details" : {
                "debut" : "18 December 1989",
                "awards" : "Bharat Ratna, Padma Bhushan, Padma Shri, Rajiv Gandhi Khel Ratna",
                "name" : "Sachin",
                "country" : "India",
                "dob" : "24 April 1973",
                "gender" : "Male",
                "age" : "42",
                "sport" : "Cricket",
                "current_status" : "retired"
              }
            },
            "person4" : {
              "details" : {
                "debut" : "23 March 1990",
                "awards" : "Padma Bhushan, Padma Shri, Rajiv Gandhi Khel Ratna, Arjuna Award",
                "name" : "Leander Paes",
                "country" : "India",
                "dob" : "17 June 1973",
                "gender" : "Male",
                "age" : "44",
                "sport" : "Badmiton",
                "current_status" : "on-ground"
              }
            }
          }
        }
      }
    ]
  }
}

Thanks in Advance

Val
  • 207,596
  • 13
  • 358
  • 360
Madhu
  • 1
  • does it work if you run the query manually? Doesn't look like a python question to me. – Nick Slavsky Jun 15 '18 at 20:35
  • You mapping is supposedly quite wrong. You seem to have indexed your mapping as a document instead of in the index itself. What do you get running `curl -XGET localhost:9200/sports` ? – Val Jun 16 '18 at 04:28
  • ```from elasticsearch import Elasticsearch import requests es = Elasticsearch() res = es.create(index="sports",doc_type="articles",body=data,id=1)```**output of curl -XGET localhost:9200/sports** ```{"sports":{"aliases":{},"mappings":{"articles":{"properties":{"mappings":{"properties":{"person1":{"properties":{"details":{"properties":{"age":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"awards":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"country":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}}``` – Madhu Jun 16 '18 at 07:34

0 Answers0