Michael Johnston
Michael Johnston

Reputation: 2382

Elasticsearch query_string with both explicit field and fields attribute

If I were to create a query like this:

"query": {
  "query_string": {
    "query": "User:mjohnst",
    "default_field": "Text",
    "fields": [
       "Text",
       "ProcessedText"
    ], 
    "default_operator": "and",
    "lowercase_expanded_terms": false
  }
}

Where the query_string -> query is specifying a field explicitly, but the fields property is set to other fields, what is the expected behavior? Will User, Text, and ProcessedText be searched, or just User?

Upvotes: 0

Views: 57

Answers (2)

imotov
imotov

Reputation: 30163

The simplest way to test it is by using validate query API:

curl "localhost:9200/test/doc/_validate/query?pretty&explain" -d '{
    "query": {
        "query_string": {
            "query": "User:mjohnst blah",
            "default_field": "Text",
            "fields": [
                "Text",
                "ProcessedText"
            ],
            "default_operator": "and",
            "lowercase_expanded_terms": false
        }
    }
}'

{
  "valid" : true,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "failed" : 0
  },
  "explanations" : [ {
    "index" : "test",
    "valid" : true,
    "explanation" : "filtered(+User:mjohnst +(Text:blah | ProcessedText:blah))->cache(_type:doc)"
  } ]
}

As you can see the term with explicitly specified field mjonst is searched against this field (User) the term blahwithout field is searched against all fields in the fields list.

Upvotes: 1

Michael Johnston
Michael Johnston

Reputation: 2382

Tested this out on some documents and it will only return the documents that match the search on just User

Upvotes: 0

Related Questions