Query string and number with match phrase


(mendy) #1

i have field with type string and the data is like

{
"extraDataTest": "my age is17 and my name is mike"
}

the data and the query contains string and numbers. the data could be also like "my age is 17 and my name is mike". i want to able to do full text search on this field.

when i do this query :
{
"from": 1,
"size": 25,
"query": {
"match": {
"extraDataTest": {
"type": "phrase",
"query": "my age is 17"
}
}
}
}

the result is empty:
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 0,
"max_score": null,
"hits": []
}
}

please help me with any idea how to deal with

regards
mendy


(Daniel Mitterdorfer) #2

Hi Mendy,

I think you just have a typo in the document that you index. Note that there is no spaced between "is" and "17" in your document but in the query there is one.

If I index a few documents:

POST /_bulk
{"index":{"_index":"my_app","_type":"people"}}
{"extraDataTest":"my age is 17 and my name is mike"}
{"index":{"_index":"my_app","_type":"people"}}
{"extraDataTest":"my age is 22 and my name is hanna"}
{"index":{"_index":"my_app","_type":"people"}}
{"extraDataTest":"my age is 13 and my name is hans"}
{"index":{"_index":"my_app","_type":"people"}}
{"extraDataTest":"my age is 88 and my name is joel"}

and then issue a query:

GET /my_app/_search
{
   "query": {
      "match": {
         "extraDataTest": {
            "query": "my age is 17",
            "type": "phrase"
         }
      }
   }
}

I get one result:

{
   "took": 2,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 1,
      "max_score": 0.28767452,
      "hits": [
         {
            "_index": "my_app",
            "_type": "people",
            "_id": "AVMx6OM9vB34i1GBuXMp",
            "_score": 0.28767452,
            "_source": {
               "extraDataTest": "my age is17 and my name is mike"
            }
         }
      ]
   }
}

Daniel


(system) #3