Created
March 13, 2012 14:36
-
-
Save anonymous/2029161 to your computer and use it in GitHub Desktop.
How to query with multiple languages (field per language approach)?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# 1. No results? | |
echo "Search 1: text: _all: topic - no results?" | |
curl -XPOST 'localhost:9200/testing/_search?pretty=true' -d ' | |
{ | |
"query": { | |
"text": { | |
"_all": "topic" | |
} | |
} | |
}' | |
echo;echo | |
# 2. OK as expected | |
echo "Search 2: fields[titles eng fin ger, _all] AND-query: topic" | |
curl -XPOST 'localhost:9200/testing/_search?pretty=true' -d ' | |
{ | |
"query": { | |
"query_string": { | |
"fields": [ | |
"title_eng", | |
"title_fin", | |
"title_ger", | |
"_all" | |
], | |
"default_operator": "AND", | |
"query": "topic" | |
} | |
} | |
}' | |
echo;echo | |
# 3. No results, why? | |
echo "Search 3: fields[titles eng fin ger, _all], AND-query: topics on vagueness" | |
curl -XPOST 'localhost:9200/testing/_search?pretty=true' -d ' | |
{ | |
"query": { | |
"query_string": { | |
"fields": [ | |
"title_eng", | |
"title_fin", | |
"title_ger", | |
"_all" | |
], | |
"default_operator": "AND", | |
"query": "topics on vagueness" | |
} | |
} | |
}' | |
echo;echo | |
# 4. works | |
echo "Search 4: like 3 but with dis_max instead of query_string" | |
curl -XPOST 'localhost:9200/testing/_search?pretty=true' -d ' | |
{ | |
"query": { | |
"dis_max": { | |
"queries": [ | |
{ | |
"text": { | |
"_all": { | |
"query": "topics on vagueness", | |
"operator": "and" | |
} | |
} | |
}, | |
{ | |
"text": { | |
"title_eng": { | |
"query": "topics on vagueness", | |
"operator": "and" | |
} | |
} | |
}, | |
{ | |
"text": { | |
"title_fin": { | |
"query": "topics on vagueness", | |
"operator": "and" | |
} | |
} | |
}, | |
{ | |
"text": { | |
"title_ger": { | |
"query": "topics on vagueness", | |
"operator": "and" | |
} | |
} | |
} | |
] | |
} | |
} | |
}' | |
echo;echo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# setup | |
echo "create index with mapping" | |
curl -XPOST 'localhost:9200/testing?pretty=true' -d ' | |
{ | |
"mappings": { | |
"record": { | |
"properties": { | |
"title": { | |
"type": "string", | |
"index": "analyzed", | |
"boost": "2.0" | |
}, | |
"title_eng": { | |
"type": "string", | |
"index": "analyzed", | |
"analyzer": "english" | |
}, | |
"title_fin": { | |
"type": "string", | |
"index": "analyzed", | |
"analyzer": "finnish" | |
}, | |
"title_ger": { | |
"type": "string", | |
"index": "analyzed", | |
"analyzer": "german" | |
} | |
} | |
} | |
} | |
}' | |
echo;echo | |
echo "post test data" | |
curl -XPOST 'http://localhost:9200/testing/record?pretty=true' -d '{ | |
"title": "Topics on Vagueness", | |
"title_eng": "Topics on Vagueness" | |
}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment