I am using elasticsearch 6.1 and I am trying to add a basic synonym filter to my settings following this doc : https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-synonym-tokenfilter.html
Here is my code :
curl -XPUT 'localhost:9200/test_index?pretty' -H 'Content-Type: application/json' -d'
{
"settings": {
"index" : {
"analysis" : {
"analyzer" : {
"search_synonyms" : {
"type": "custom",
"tokenizer" : "keyword",
"filter" : ["lowercase","synonyms"]
}
},
"filter" : {
"synonyms" : {
"type" : "synonym",
"synonyms_path" : "analysis/synonyms.txt"
}
}
}
}
}
}'
And I get the following error message :
{
"error" : {
"root_cause" : [
{
"type" : "illegal_argument_exception",
"reason" : "IOException while reading synonyms_path_path: /usr/share/elasticsearch/config/analysis/synonyms.txt"
}
],
"type" : "illegal_argument_exception",
"reason" : "IOException while reading synonyms_path_path: /usr/share/elasticsearch/config/analysis/synonyms.txt",
"caused_by" : {
"type" : "no_such_file_exception",
"reason" : "/usr/share/elasticsearch/config/analysis/synonyms.txt"
}
},
"status" : 400
}
I believe the issue comes from the "... reading synonyms_path_path:" which should probably be just "... reading synonyms_path:".
However, I believe I respected all features as mentioned in the doc.
Moreover, if I try just to put :
"filter" : {
"synonyms" : {
"type" : "synonym",
"synonyms" : "analysis/synonyms.txt"
}
}
It just does not read the file then...
My synonyms.txt is the exact same file as shown in the doc for solr format.
Any thoughts or suggestion on how to fix this?
Thank you very much in advance for you time.
By using the following command on file, I fixed the error message :
sudo chmod 777 synonyms.txt
But the analyzer still does not recognize the synonyms present in the file.
Indeed synonyms.txt contains : i-pod, i pod => ipod
And if I try :
curl -XGET 'localhost:9200/test_index/_analyze?pretty' -H 'Content-Type: application/json' -d'
{
"analyzer": "search_synonyms",
"text": "i pod"
}'
I get :
{
"tokens" : [
{
"token" : "i pod",
"start_offset" : 0,
"end_offset" : 5,
"type" : "word",
"position" : 0
}
]
}
Problem not yet entirely solved, but getting there :).
"filter" : {
"synonyms" : {
"type" : "synonym",
"synonyms" : "synonyms.txt"
}
}
Try this. It worked for me.
Little late, but I had the same issue with docker, as Aurelien Quillet pointed out.
You probably need something like
services:
elasticsearch_container:
volumes:
- ${APPLICATION}/config/packages/synonyms.txt:/usr/share/elasticsearch/config/synonyms.txt
In my case ${APPLICATION}/config/packages/synonyms.txt is the path in my project code.
The path shown in the error (/usr/share/elasticsearch/config/synonyms.txt) is the path in my elasticsearch container.
Related
I am currently creating a passcard for my app but unfortunately, it is not working. Passcard is not showing in the simulator when dragging it or event downloading it from my email. My pass.json codes are below.
"formatVersion" : 1,
"passTypeIdentifier" : "pass.com.example",
"serialNumber" : "0000000",
"teamIdentifier" : "xxxxxxxx",
"barcode" : {
"message" : "123456789",
"format" : "PKBarcodeFormatPDF417",
"messageEncoding" : "iso-8859-1",
},
"organizationName" : "companyname",
"description" : "companytagline",
"logoText" : "companyname",
"foregroundColor" : "rgb(255,255,255)",
"backgroundColor": "rgb(0,100,0)",
"generic" : {
"auxiliaryFields" : [
{
"key" : "patientName",
"label" : "NAME",
"value" : "Retail Pharmacy 1, Test Patient"
},
{
"key" : "gender",
"label" : "GENDER",
"value" : "Female"
}
],
}
}
This is what I have in my Terminal
hopprlabs-iMac:Desktop developer1$ ./signpass -p healthpass.raw/
2019-02-19 10:10:39.483 signpass[2096:231781] {
".DS_Store" = df2fbeb1400acda0909a32c1cf6bf492f1121e07;
"Icon.png" = 295cb779e5e185efefd6c5e9a2a94c3352e51b2a;
"Icon#2x.png" = 987db966ddc28a72d6bfd15a6565d191be06d0f0;
"pass.json" = 3e66cf17f758939547932654c3394e42470d1c94;
"thumbnail.png" = 2a616d4490d1e12d81ddb0610df6b992ad79aeca;
}
Thanks for emailing that through. Having looked at the package, it seems there is a problem with your icon file.
The iPhone reports this error like this:
Invalid data error reading pass pass.com./0000000. Pass does not contain icon.png/icon#2x.png/icon#3x.png
I suggest making your icon file names lower case, so icon.png instead of Icon.png.
I would also include the #3x size file too.
How could I query this data in this way:
I would like to ignore the CurrentSubAdministrativeArea child and iterate every each sub child and find the right userKey
Actually I'm using this code, that isnt working:
self.ref.child("Ads").child("CurrentSubAdministrativeArea")
/*HERE I would like to ignore the childs*/
.queryOrdered(byChild: "userKey").queryEqual(toValue: uid).observeSingleEvent(of:.value, with: { (snapshot) in
--
{
"Ads" : {
"CurrentSubAdministrativeArea" : {
"Mantova" : {
"-L7ymBmmbHkNfhBRte9F" : {
"cost" : 200,
"date" : 1527256922000,
"info" : "Test",
"maxLimit" : 100,
"minLimit" : 10,
"personBadType" : [ "abitudinaria", "antipatica" ],
"personGoodType" : [ "simpatica", "felice" ],
"subAdministrativeArea" : "Mantova",
"title" : "Mantova Test",
"url" : "https://firebasestorage.googleapis.com/v0/b/team-34540.appspot.com/o/Mantova%20Test?alt=media&token=3a81ed1c-ecd6-4dc0-bd7c-45e093ce8188",
"userKey" : "OsJRc98sqxPx70iqxFtoqerMzHH2",
"via" : "viale dei test"
}
},
"Milano" : {
"-L6qywMC6nxi0fJNMHba" : {
"cost" : 454,
"date" : 1528298580000,
"info" : "Di pollo",
"maxLimit" : 100,
"minLimit" : 10,
"personBadType" : [ "abitudinaria", "antipatica" ],
"personGoodType" : [ "simpatica", "felice" ],
"subAdministrativeArea" : "Milano",
"title" : "Pollo 2",
"url" : "https://firebasestorage.googleapis.com/v0/b/team-34540.appspot.com/o/Pollo?alt=media&token=fc6a3ec8-5f9a-4347-bdad-2d9715af784d",
"userKey" : "OsJRc98sqxPx70iqxFtoqerMzHH2",
"via" : "viale test"
}
}
}
}
}
You could denormalize your data in such a way your query is easy to build and execute.
Together with the data structure you already have you would have another node (ie. another data structure) like
{
"AdsByUsers" : {
"OsJRc98sqxPx70iqxFtoqerMzHH2": {
"Mantova",
"Milano",
...
},
"abcde88qxPx70iqxFtoqerMzKh5": {
"Firenze",
...
}
With NoSQL database you should not hesitate to duplicate data in such a way your queries are easy and fast to execute.
Within the browser for my jenkins job I'm running the following query.
lastStableBuild/api/json?pretty=true&tree=actions[buildsByBranchName[*[*]]]
Results from the above query
{
"_class" : "hudson.model.FreeStyleBuild",
"actions" : [
{
"_class" : "hudson.model.CauseAction"
},
{
},
{
"_class" : "jenkins.metrics.impl.TimeInQueueAction"
},
{
},
{
"_class" : "hudson.plugins.git.util.BuildData",
"buildsByBranchName" : {
"my-branch-name" : {
"_class" : "hudson.plugins.git.util.Build",
"buildNumber" : 587,
"buildResult" : null,
"marked" : {
"SHA1" : "***",
"branch" : [
{
}
]
},
"revision" : {
"SHA1" : "***",
"branch" : [
{
}
]
}
},
"my-other-branch-name" : {
"_class" : "hudson.plugins.git.util.Build",
"buildNumber" : 1373,
"buildResult" : null,
"marked" : {
"SHA1" : "***",
"branch" : [
{
}
]
},
"revision" : {
"SHA1" : "***",
"branch" : [
{
}
]
}
},
I would like to be able to narrow it down to just the build number like you would get with
/lastSuccessBuild/buildNumber
using the api but I would settle for just everything inside of the branch name key so that I wouldn't have to loop through all branches and compare the name. I'm assuming I can narrow it down more where I have my "*" specified but can't figure out the right syntax to use.
I got that info from here instead.
tree=actions[lastBuiltRevision[*,branch[*]]]
Either way, if you want the branch info, from inside the buildsByBranchName section of the tree, you will have to query it as I did above.
If you don't mind getting your answer back in xml, xpath works very well.
For the url:
/lastStableBuild/api/xml?xpath=//buildsByBranchName&wrapper=meep
Creates an xml that looks like:
<meep>
<buildsByBranchName>
...
</buildsByBranchName>
</meep>
And will be populated with the buildsByBranchName (NOTE: there may be more than one if there are multiple git remotes, hence the need for a wrapper) for the specified last successful build of the job specified in the url. You can substitute anything for the word "meep", that will become the wrapper object for the newly created xml object.
My problem is the following:
I run an elasticsearch query in a rails app using specific settings to my index and my search analyzer, the problem is that it doesnt return any results in the app, in the other hand when i try to run it directly from my elasticsearch docker, i have tokens returned. If i use these tokens in my app query, i get results...
so this is my elasticsearch query:
curl -XGET 'localhost:9200/development-stoot-services/_analyze?analyzer=search_francais' -d 'cours de guitare'
{"tokens":[{"token":"cour","start_offset":0,"end_offset":5,"type":"<ALPHANUM>","position":1},{"token":"guitar","start_offset":9,"end_offset":16,"type":"<ALPHANUM>","position":3}]}
here is the query from my rails app to elasticsearch:
query = {
"query" : {
"bool" : {
"must" : [
{
"range" : {
"deadline" : {
"gte" : "2016-05-26T10:27:19+02:00"
}
}
},
{
"terms" : {
"state" : [
"open"
]
}
},
{
"query_string" : {
"query" : "cours de guitare",
"default_operator" : "AND",
"fields" : [
"title",
"description",
"brand",
"category_name"
]
}
}
]
}
},
"filter" : {
"and" : [
{
"geo_distance" : {
"distance" : "40km",
"location" : {
"lat" : 48.855736,
"lon" : 2.32927300000006
}
}
}
]
},
"sort" : [
{
"created_at" : "desc"
}
]
}
the last query does not return any result, but if i try a query with the tokens returned by elasticsearch ('cour', 'guitar') i have expected results. So i guess there is a problem between rails and elasticsearch that i dont find...
Can anyone help on that ?
Try to modify your query like this, i.e. you need to specify the search_francais analyzer in your query_string in order to analyze cours de guitare the same way you did with the _analyze endpoint:
...
{
"query_string" : {
"query" : "cours de guitare",
"default_operator" : "AND",
"analyzer": "search_francais", <--- add this line
"fields" : [
"title",
"description",
"brand",
"category_name"
]
}
},
...
I have the following code in the custom ES 'where' wrapper method
filter: { term: params }
Then we have a sample ES document that contains:
"emails" => { "email" => "johndoe#email.com" }
It is returned when my search is:
query.where("emails.email" => "johndoe")
but I get no results when:
query.where("emails.email" => "johndoe#email.com")
It seems like I have to escape at symbol somehow when using ES gem?
It's probably because your field is analyzed using the default standard analyzer and is thus tokenized at the # sign.
You can see what ES has indexed by running the command below:
curl -XGET 'localhost:9200/_analyze?analyzer=standard&pretty' -d 'johndoe#email.com'
And the result is
{
"tokens" : [ {
"token" : "johndoe",
"start_offset" : 0,
"end_offset" : 7,
"type" : "<ALPHANUM>",
"position" : 1
}, {
"token" : "email.com",
"start_offset" : 8,
"end_offset" : 17,
"type" : "<ALPHANUM>",
"position" : 2
} ]
}
As you can see, your email field has been tokenized as two different tokens and that's probably why searching for johndoe works, while searching for the full email address doesn't.
There are a few ways out from here, but one way that would work is to create your own analyzer based on a pattern_capture token filter and use it as index_analyzer for your emails.email field.
{
"settings" : {
"analysis" : {
"filter" : {
"email" : {
"type" : "pattern_capture",
"preserve_original" : 1,
"patterns" : [ "([^#]+)", "(\\p{L}+)", "(\\d+)", "#(.+)" ]
}
},
"analyzer" : {
"email" : {
"tokenizer" : "uax_url_email",
"filter" : [ "email", "lowercase", "unique" ]
}
}
}
},
"mappings": {
"emails": {
"properties": {
"email": {
"type": "string",
"analyzer": "email" <-- use the analyzer here
}
}
}
}
}
At indexing time, that analyzer will produce all of the following tokens, which will allow you to search for any parts of your email address:
johndoe#email.com
johndoe
email.com
email
com