I want to retrieve data from elastic search. I indexed data in elastc search and it look like below
{
"_index": "user",
"_type": "user_type",
"_id": "2393294",
"_version": 1,
"_score": 2,
"_source": {
"name": "shwn decker",
"worksFor": {
"legalName": "nykc private fund",
"address": "Mk street, bruke field"
},
},
"fields": {
"tweetDate": [
1457481600000
]
},
"sample_date":"10/10/2013"
}
I want to search the data based on the field "name" and "legalName". I tried some queries but when I am trying to filter data based on both field then no document is getting matched. Query which I used is:
curl -XGET 'localhost:9200/user/user_type/_search?pretty' -H 'Content- Type: application/json' -d'
{
"query":{
"bool":{
"must":{
"query_string": {
"query": "shwn decker",
"fields": ["name"]
}
},
"filter":{
"term":{
"worksFor.legalName":"nykc private fund"
}
}
}
}
}'
What modification I should do in the query so that I can get the result. I am using customized mapping for this data which is shown below:
{
"settings":
{
"number_of_shards" : 3,
"number_of_replicas" : 2
},
"mappings" : {
"user_type" : {
"properties" : {
"name" : {
"type" : "text",
"fields" : {
"raw" : {
"type":"keyword"
}
}
},
"worksFor" : {
"properties" : {
"address" : {
"type" : "text"
},
"legalName" : {
"type" : "text",
"fields" : {
"raw" : {
"type":"keyword"
}
}
},
}
}
}
}
}
}'