ropensci / elastic

R client for the Elasticsearch HTTP API
https://docs.ropensci.org/elastic
Other
245 stars 58 forks source link

Strict/Fixed query matching #170

Closed komalsrathi closed 7 years ago

komalsrathi commented 7 years ago

I am trying to query the database using:

out <- Search(index = index, type = type, q = "gene_info.symbol:(A2M)", body = body, raw = TRUE)

The problem is I am not just getting strict matching and it returns A2M as well as A2M-AS1. What's more confusing is that if I query for A2M-AS1, I still get both. I tried this with other gene symbols like A1BG and A1BG-AS1 and still facing the issue.

{
  "gene_info": {
    "symbol": "A2M"
  }
}
{
  "gene_info": {
    "symbol": "A2M-AS1"
  }
}

Could it be related to the database schema?

Any help would be much appreciated!

sckott commented 7 years ago

hi @komalsrathi ! thanks for your question 😸

can you share your elastic pkg version and Elasticsearch version with me?

Does elastic R pkg and doing the same query in browser or with e.g., curl on command line give the same answer?

komalsrathi commented 7 years ago

R package version: elastic_0.7.8.9499. I am pretty sure my Elastic search version is >=5 because I don't have nested querying enabled which is why I cannot do simple curl statements - I think that is something the admin is working on currenly. However the same query in the browser, returns the same output as elastic R package.

sckott commented 7 years ago

thx, can get Elasticsearch ver doing elastic::ping()

komalsrathi commented 7 years ago

Thanks! It is 5.2.2

sckott commented 7 years ago

try this for example

library(elastic)
connect()

plosdat <- system.file("examples", "plos_data.json", package = "elastic")
invisible(docs_bulk(plosdat))

body <- '{
 "query":{
   "bool" : {
     "should" : {
        "match" : {
          "title" : "cells"
        }
     }
  }
}}'
Search("plos", body = body)

should do exact match for you

komalsrathi commented 7 years ago

Another question - can you do this for nested queries as well?

sckott commented 7 years ago

you should be able to do anything you can do as if you were doing curl requests or using python library, etc