简体   繁体   中英

Elasticsearch: filter by any field

I am playing with filters in elasticsearch (we use old version 1.3.1), and I need to filter my search results by any field. With query, this can be done like this:

"query": {
  "query_string": {
    "query": "_all:test"
  }
}

But filters seems to not work with _all statement. What can I do? Would newer elasticsearch version solve my problem?

Thanks in advance!

PS: I need to search exact values, so I cannot use queries. There is difference between queries and filters - if you search for my brown , then you can expect results like:

my brown

This is my brown dog.

someone stolen my brown wallet

But filter will return only my brown , and that is what I need.

You might want to read up a little on the distinction between queries and filters . What you're doing there is a query string query .

If you do actually want to filter against exact text tokens (read up on analysis if you don't know what I mean by "tokens"), AND you have your mapping set up such that the "_all" field behaves as you're expecting then try something like this:

POST /test_index/_search
{
   "query": {
      "filtered": {
         "filter": {
            "term": {
               "_all": "test"
            }
         }
      }
   }
}

If, on the other hand, you want to allow some analysis (so that "Test" is tokenized to "test" , for example), you may want this instead:

POST /test_index/_search
{
   "query": {
      "match": {
         "_all": "Test"
      }
   }
}

Here is some code I used to play around with it:

http://sense.qbox.io/gist/44adf2c2ade8abd6758f0e08ed2e40434850fc1c

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM