Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

multi_match vs query_string problem #201

Open
caherrerapa opened this issue Dec 27, 2015 · 3 comments
Open

multi_match vs query_string problem #201

caherrerapa opened this issue Dec 27, 2015 · 3 comments

Comments

@caherrerapa
Copy link

Note: I'm not sure if this is the right place to ask this, but here it goes as i haven't found any specific documentation for my case in the official site

I'm not sure why i can't get this to work. I want to be able to search in all the fields including the attachment

When i do as follows i get 1 result as expected

query: { query_string: "keyword" }

But, when i do the following i get 0 results

query: { 
               multi_match: 
               {   
                  query: "keyword",
                  type: 'best_fields',
                  fields: ["name^10", "email^9", "phone", "address", "resume_encoded", "cover_letter_encoded"],
                  operator: 'and'
              }       
}

This is my mapping

mapping do
      indexes :id, index: :not_analyzed
      indexes :name
      indexes :email
      indexes :phone
      indexes :address
      indexes :created_at, type: 'date'
      indexes :updated_at, type: 'date'

      indexes :position do
        indexes :id,    type: 'integer'
        indexes :name,  type: 'string', index: :not_analyzed
      end
      indexes :stage do
        indexes :id,    type: 'integer'
        indexes :name,  type: 'string', index: :not_analyzed
      end
      indexes :source do
        indexes :id,    type: 'integer'
        indexes :name,  type: 'string', index: :not_analyzed
      end
      indexes :resume_encoded, type: 'attachment'
      indexes :cover_letter_encoded, type: 'attachment'
end

def resume_encoded
      if self.resume.present?
        ::Base64.encode64(self.resume.read)
      else
        ""
      end
end

def cover_letter_encoded
      if self.cover_letter.present?
        ::Base64.encode64(self.cover_letter.read)
      else
        ""
      end
end

def as_indexed_json(options = {})
      self.as_json(only: [:id, :name, :email, :phone, :address, :summary, :created_at, :updated_at, :resume_content],
                   methods: [:resume_encoded, :cover_letter_encoded],
                   include: {
                     position: {only: [:id, :name]},
                     stage: {only: [:id, :name]},
                     source: {only: [:id, :name]}
                   })
end

Any lights / help would be appreciated. Im not sure if what i'm trying to do is legit

@dadoonet
Copy link
Member

You should ask first on discuss.elastic.co as more people will see your question and might be able to help.

Wondering what gives the following request:

GET test/doc/_search
{
  "query": {
    "match": {
      "resume_encoded": "keyword"
    }
  }
}

@ilkermutlu
Copy link

@caherrerapa Did you find a solution yet? I'm having the same issue.

@ilkermutlu
Copy link

@caherrerapa may be this could help you:

My encoded field was named content and was mapped using:
"content": { "type": "attachment", "fields": { "content": { "type": "string", "analyzer": "turkish", "term_vector":"with_positions_offsets", "store": true } } },

I was trying to do a query using:
"multi_match": { "query": "some query", "fields": [ "author.name^2", "content" ] }
and got 0 results like you did.

The correct query should've been:
"multi_match": { "query": "some query", "fields": [ "author.name^2", "content.content" ] }

This solved my case, not sure about yours as our mappings are a little different.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants