Elasticsearch term query does not give any results -


i new elasticsearch , have perform following query:

get book-lists/book-list/_search {      "query":{         "filtered":{            "filter":{               "bool":{                  "must":[                     {                        "term":{                           "title":"sociology"                      }                   },                   {                        "term":{                           "idowner":"17xxxxxxxxxxxx45"                      }                   }                ]             }          }       }    } } 

according elasticsearch api, equivalent pseudo-sql:

select document   book-lists  title = "sociology"        , idowner = 17xxxxxxxxxxxx45 

the problem document looks this:

{      "_index":"book-lists",    "_type":"book-list",    "_id":"avbrsvhixb7carzwceps",    "_version":1,    "_score":1,    "_source":{         "title":"sociology",       "books":[            {               "title":"the tipping point: how little things can make big difference",             "isread":true,             "summary":"lorem ipsum",             "rating":3.5          }       ],       "numberviews":0,       "idowner":"17xxxxxxxxxxxx45"    } } 

and elasticsearch query above doesn't return anything.

whereas, query returns document above:

get book-lists/book-list/_search {      "query":{         "filtered":{            "filter":{               "bool":{                  "must":[                     {                        "term":{                           "numberviews":"0"                      }                   },                   {                        "term":{                           "idowner":"17xxxxxxxxxxxx45"                      }                   }                ]             }          }       }    } } 

this makes me suspect fact "title" same name 2 fields something.

is there way fix without having rename of fields. or missing somewhere else?

thanks trying help.

your problem described in documentation.

i suspect don't have explicit mapping on index, means elasticsearch use dynamic mapping.

for string fields, pass string through standard analyzer lowercases (among other things). why query doesn't work.

your options are:

  1. specify explicit mapping on field isn't analyzed before storing in index (index: not_analyzed).
  2. clean term query before sending elasticsearch (in specific query lowercasing work, note standard analyzer other things remove stop words, depending on title may still have issues).
  3. use different query type (e.g., query_string instead of term analyze query before running it).

looking @ sort of data storing need specify explicit not_analyzed mapping.

for option 3 query this:

{      "query":{         "filtered":{            "filter":{               "bool":{                  "must":[                     {                        "query_string":{                           "fields": ["title"],                         "analyzer": "standard",                         "query": "sociology"                      }                   },                   {                        "term":{                           "idowner":"17xxxxxxxxxxxx45"                      }                   }                ]             }          }       }    } } 

note query_string query has special syntax (e.g., or , and not treated literals) means have careful give it. reason explicit mapping term filter more appropriate use case.


Comments

Popular posts from this blog

How to show in django cms breadcrumbs full path? -

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -